]> Cypherpunks repositories - gostls13.git/commitdiff
go/types: fix potential bugs in santitizer pass
authorRob Findley <rfindley@google.com>
Wed, 5 May 2021 19:01:37 +0000 (15:01 -0400)
committerRobert Findley <rfindley@google.com>
Wed, 5 May 2021 19:17:46 +0000 (19:17 +0000)
This is a port of CL 317329 to go/types.

Change-Id: I1ba65284c91044f0ceed536da4149ef25e1f9502
Reviewed-on: https://go-review.googlesource.com/c/go/+/317291
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
src/go/types/sanitize.go

index 3429867321bb882502f6168b0c2459075cb75798..b905972d367e660d46be14eed56e242ac192469d 100644 (file)
@@ -67,13 +67,17 @@ func sanitizeInfo(info *Info) {
 type sanitizer map[Type]Type
 
 func (s sanitizer) typ(typ Type) Type {
+       if typ == nil {
+               return nil
+       }
+
        if t, found := s[typ]; found {
                return t
        }
        s[typ] = typ
 
        switch t := typ.(type) {
-       case nil, *Basic, *bottom, *top:
+       case *Basic, *bottom, *top:
                // nothing to do
 
        case *Array:
@@ -107,10 +111,14 @@ func (s sanitizer) typ(typ Type) Type {
 
        case *Interface:
                s.funcList(t.methods)
-               s.typ(t.types)
+               if types := s.typ(t.types); types != t.types {
+                       t.types = types
+               }
                s.typeList(t.embeddeds)
                s.funcList(t.allMethods)
-               s.typ(t.allTypes)
+               if allTypes := s.typ(t.allTypes); allTypes != t.allTypes {
+                       t.allTypes = allTypes
+               }
 
        case *Map:
                if key := s.typ(t.key); key != t.key {