From: Rob Findley Date: Thu, 27 May 2021 16:35:01 +0000 (-0400) Subject: go/types: guard against check==nil in newNamed X-Git-Tag: go1.17beta1~82 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=6b8c94b6c524710bc3290546176a0da2f7c8c9db;p=gostls13.git go/types: guard against check==nil in newNamed 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 Run-TryBot: Robert Findley TryBot-Result: Go Bot Reviewed-by: Robert Griesemer --- diff --git a/src/go/types/type.go b/src/go/types/type.go index 3fdb2365a0..2660ce4408 100644 --- a/src/go/types/type.go +++ b/src/go/types/type.go @@ -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 }