]> Cypherpunks.ru repositories - gostls13.git/commitdiff
go/types: make sure we are safe for nil in underIs
authorRobert Griesemer <gri@golang.org>
Wed, 17 Nov 2021 01:51:58 +0000 (17:51 -0800)
committerRobert Griesemer <gri@golang.org>
Wed, 17 Nov 2021 04:32:11 +0000 (04:32 +0000)
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 <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
src/go/types/expr.go
src/go/types/predicates.go
src/go/types/type.go

index 660c92de3b3dc0745060ed112a7a354ea7651059..ddb0149bf49b45af3d10222ab5af26f130e01a34 100644 (file)
@@ -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
                })
index d0697b1ad7028a43869df24978e73a501e384ed8..78ad6c4f231c855ebde212a006b71c0e3a2178a1 100644 (file)
@@ -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
 }
index 555eb9e8b9934383fc53a6e7a9abe63d42947ffd..756bdcf0a57fc0f980a8738a03ea9bf326ef3287 100644 (file)
@@ -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 {