]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/types2: make sure we are safe for nil in underIs
authorRobert Griesemer <gri@golang.org>
Fri, 12 Nov 2021 21:23:45 +0000 (13:23 -0800)
committerRobert Griesemer <gri@golang.org>
Fri, 12 Nov 2021 23:26:33 +0000 (23:26 +0000)
Reviewed all uses of underIs (global function and method) and made
sure we are ok with a nil incoming argument (indicating a type set
with no specific types).

Added a couple of checks where we didn't have them (and somehow
didn't run into a problem yet).

Change-Id: Ifde45a3a80ddf2b1a19c83f79258ad8207dfb09f
Reviewed-on: https://go-review.googlesource.com/c/go/+/363658
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
src/cmd/compile/internal/types2/expr.go
src/cmd/compile/internal/types2/predicates.go
src/cmd/compile/internal/types2/type.go

index f86606375c7959e9415c5a411bab403d3c968e92..77e497b9cca309a01baf5d4efbef689963a24188 100644 (file)
@@ -740,6 +740,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 5cb1c33814ab495614f968de32f8f00104a51ed0..ab490372fca565a6e5ee451ca425c8c3f53d862f 100644 (file)
@@ -147,7 +147,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 24d44442e91282e73713fa1e986e35a93ef1863c..ba260d2b7d281be3741fb9645b36d1d62b6869fd 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 {