diff --git a/src/go/types/expr.go b/src/go/types/expr.go index 660c92de3b..ddb0149bf4 100644 --- a/src/go/types/expr.go +++ b/src/go/types/expr.go @@ -679,6 +679,9 @@ func (check *Checker) implicitTypeAndValue(x *operand, target Type) (Type, const case *TypeParam: // TODO(gri) review this code - doesn't look quite right ok := u.underIs(func(t Type) bool { + if t == nil { + return false + } target, _, _ := check.implicitTypeAndValue(x, t) return target != nil }) diff --git a/src/go/types/predicates.go b/src/go/types/predicates.go index d0697b1ad7..78ad6c4f23 100644 --- a/src/go/types/predicates.go +++ b/src/go/types/predicates.go @@ -149,7 +149,9 @@ func hasNil(t Type) bool { case *Slice, *Pointer, *Signature, *Interface, *Map, *Chan: return true case *TypeParam: - return u.underIs(hasNil) + return u.underIs(func(u Type) bool { + return u != nil && hasNil(u) + }) } return false } diff --git a/src/go/types/type.go b/src/go/types/type.go index 555eb9e8b9..756bdcf0a5 100644 --- a/src/go/types/type.go +++ b/src/go/types/type.go @@ -65,6 +65,9 @@ func match(x, y Type) Type { func structuralType(typ Type) Type { var su Type if underIs(typ, func(u Type) bool { + if u == nil { + return false + } if su != nil { u = match(su, u) if u == nil {