Skip to content

Commit 03dd049

Browse files
committed
go/types: make sure we are safe for nil in underIs
This CL is a clean port CL 363658 from types2 to go/types. Change-Id: Ie2032f85a9cfca62161c2e629c78f1ecd8c6e4c0 Reviewed-on: https://go-review.googlesource.com/c/go/+/364537 Trust: Robert Griesemer <[email protected]> Reviewed-by: Robert Findley <[email protected]>
1 parent 3c00a28 commit 03dd049

3 files changed

Lines changed: 9 additions & 1 deletion

File tree

src/go/types/expr.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,9 @@ func (check *Checker) implicitTypeAndValue(x *operand, target Type) (Type, const
679679
case *TypeParam:
680680
// TODO(gri) review this code - doesn't look quite right
681681
ok := u.underIs(func(t Type) bool {
682+
if t == nil {
683+
return false
684+
}
682685
target, _, _ := check.implicitTypeAndValue(x, t)
683686
return target != nil
684687
})

src/go/types/predicates.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,9 @@ func hasNil(t Type) bool {
149149
case *Slice, *Pointer, *Signature, *Interface, *Map, *Chan:
150150
return true
151151
case *TypeParam:
152-
return u.underIs(hasNil)
152+
return u.underIs(func(u Type) bool {
153+
return u != nil && hasNil(u)
154+
})
153155
}
154156
return false
155157
}

src/go/types/type.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ func match(x, y Type) Type {
6565
func structuralType(typ Type) Type {
6666
var su Type
6767
if underIs(typ, func(u Type) bool {
68+
if u == nil {
69+
return false
70+
}
6871
if su != nil {
6972
u = match(su, u)
7073
if u == nil {

0 commit comments

Comments
 (0)