]> Cypherpunks repositories - gostls13.git/commitdiff
go/types: guard against check==nil in newNamed
authorRob Findley <rfindley@google.com>
Thu, 27 May 2021 16:35:01 +0000 (12:35 -0400)
committerRobert Findley <rfindley@google.com>
Thu, 27 May 2021 17:28:26 +0000 (17:28 +0000)
When importing generic named types, it is possible for Checker.newNamed
to be called during type instantiation when the Checker is nil.

In this case we should be able to safely skip this delayed expansion.

Updates #45580

Change-Id: I75422100464d57eba24642c93e06e8b47d904fc3
Reviewed-on: https://go-review.googlesource.com/c/go/+/322974
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
src/go/types/type.go

index 3fdb2365a03ecac28a926b1bcd7ab66a8a319bc5..2660ce4408c1b640f67bf517ca72d3819055907e 100644 (file)
@@ -661,11 +661,7 @@ func NewNamed(obj *TypeName, underlying Type, methods []*Func) *Named {
        if _, ok := underlying.(*Named); ok {
                panic("types.NewNamed: underlying type must not be *Named")
        }
-       typ := &Named{obj: obj, orig: underlying, underlying: underlying, methods: methods}
-       if obj.typ == nil {
-               obj.typ = typ
-       }
-       return typ
+       return (*Checker)(nil).newNamed(obj, underlying, methods)
 }
 
 func (check *Checker) newNamed(obj *TypeName, underlying Type, methods []*Func) *Named {
@@ -681,13 +677,15 @@ func (check *Checker) newNamed(obj *TypeName, underlying Type, methods []*Func)
        //
        // TODO(rFindley): clean this up so that under is the only function mutating
        //                 named types.
-       check.later(func() {
-               switch typ.under().(type) {
-               case *Named, *instance:
-                       panic("internal error: unexpanded underlying type")
-               }
-               typ.check = nil
-       })
+       if check != nil {
+               check.later(func() {
+                       switch typ.under().(type) {
+                       case *Named, *instance:
+                               panic("internal error: unexpanded underlying type")
+                       }
+                       typ.check = nil
+               })
+       }
        return typ
 }