1
0
mirror of https://github.com/golang/go synced 2024-11-26 11:38:01 -07:00

go/types: fix potential bugs in santitizer pass

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>
This commit is contained in:
Rob Findley 2021-05-05 15:01:37 -04:00 committed by Robert Findley
parent 40d5e6d4e2
commit 543e098320

View File

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