Skip to content

Commit

Permalink
cty: NilType.Equals(...) without a panic
Browse files Browse the repository at this point in the history
  • Loading branch information
radeksimko authored Nov 10, 2020
1 parent 3293c1b commit 1338293
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cty/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ func (t typeImplSigil) isTypeImpl() typeImplSigil {
// Equals returns true if the other given Type exactly equals the receiver
// type.
func (t Type) Equals(other Type) bool {
if t == NilType || other == NilType {
return t == other
}
return t.typeImpl.Equals(other)
}

Expand Down
7 changes: 7 additions & 0 deletions cty/type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,10 @@ func TestHasDynamicTypes(t *testing.T) {
})
}
}

func TestNilTypeEquals(t *testing.T) {
var typ Type
if !typ.Equals(NilType) {
t.Fatal("expected NilTypes to equal")
}
}

0 comments on commit 1338293

Please sign in to comment.