Skip to content

Commit 6b8c94b

Browse files
committed
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 <[email protected]> Run-TryBot: Robert Findley <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Robert Griesemer <[email protected]>
1 parent fca7b8f commit 6b8c94b

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

src/go/types/type.go

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -661,11 +661,7 @@ func NewNamed(obj *TypeName, underlying Type, methods []*Func) *Named {
661661
if _, ok := underlying.(*Named); ok {
662662
panic("types.NewNamed: underlying type must not be *Named")
663663
}
664-
typ := &Named{obj: obj, orig: underlying, underlying: underlying, methods: methods}
665-
if obj.typ == nil {
666-
obj.typ = typ
667-
}
668-
return typ
664+
return (*Checker)(nil).newNamed(obj, underlying, methods)
669665
}
670666

671667
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)
681677
//
682678
// TODO(rFindley): clean this up so that under is the only function mutating
683679
// named types.
684-
check.later(func() {
685-
switch typ.under().(type) {
686-
case *Named, *instance:
687-
panic("internal error: unexpanded underlying type")
688-
}
689-
typ.check = nil
690-
})
680+
if check != nil {
681+
check.later(func() {
682+
switch typ.under().(type) {
683+
case *Named, *instance:
684+
panic("internal error: unexpanded underlying type")
685+
}
686+
typ.check = nil
687+
})
688+
}
691689
return typ
692690
}
693691

0 commit comments

Comments
 (0)