aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDan Scales <danscales@google.com>2022-01-07 12:22:24 -0800
committerDan Scales <danscales@google.com>2022-01-11 21:56:11 +0000
commit13c912d19252b9225fa96b9a5557575bbaffb570 (patch)
tree0142a4bb131ae6621367f97080164495396763ca /src
parentad7eae21d5e75a0b1fe89db5f299490d6273c4cf (diff)
downloadgo-13c912d19252b9225fa96b9a5557575bbaffb570.tar.gz
go-13c912d19252b9225fa96b9a5557575bbaffb570.zip
cmd/compile: in typ0(), load base type before checking s.Def
The loading of the base type in typ0() may cause s.Def to be defined for the instantiated type, so load the base type before checking s.Def. Fixes #50486 Change-Id: Ic039bc8f774dda534f4ccd1f920220b7a10dede6 Reviewed-on: https://go-review.googlesource.com/c/go/+/377094 Trust: Dan Scales <danscales@google.com> Run-TryBot: Dan Scales <danscales@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'src')
-rw-r--r--src/cmd/compile/internal/noder/types.go13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/cmd/compile/internal/noder/types.go b/src/cmd/compile/internal/noder/types.go
index ed816b4955..3f3c9566ca 100644
--- a/src/cmd/compile/internal/noder/types.go
+++ b/src/cmd/compile/internal/noder/types.go
@@ -113,6 +113,15 @@ func (g *irgen) typ0(typ types2.Type) *types.Type {
// based on the names of the type arguments.
instName := g.instTypeName2(typ.Obj().Name(), typ.TypeArgs())
s := g.pkg(typ.Obj().Pkg()).Lookup(instName)
+
+ // Make sure the base generic type exists in type1 (it may
+ // not yet if we are referecing an imported generic type, as
+ // opposed to a generic type declared in this package). Make
+ // sure to do this lookup before checking s.Def, in case
+ // s.Def gets defined while importing base (if an imported
+ // type). (Issue #50486).
+ base := g.obj(typ.Origin().Obj())
+
if s.Def != nil {
// We have already encountered this instantiation.
// Use the type we previously created, since there
@@ -120,10 +129,6 @@ func (g *irgen) typ0(typ types2.Type) *types.Type {
return s.Def.Type()
}
- // Make sure the base generic type exists in type1 (it may
- // not yet if we are referecing an imported generic type, as
- // opposed to a generic type declared in this package).
- base := g.obj(typ.Origin().Obj())
if base.Class == ir.PAUTO {
// If the base type is a local type, we want to pop
// this instantiated type symbol/definition when we