cmd/compile: fix creation of named generic types (setting of t.nod)

The correct setting of t.nod is needed when exporting types. Make sure
we create instantiated named types correctly so t.nod is set.

New test file interfacearg.go that tests this (by instantiating a type
with an interface). Also has tests for various kinds of method
expressions.

Change-Id: Ia7fd9debd495336b73788af9e35d72331bb7d2b5
Reviewed-on: https://go-review.googlesource.com/c/go/+/305730
Run-TryBot: Dan Scales <danscales@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Dan Scales <danscales@google.com>
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
Dan Scales 2021-03-10 15:25:21 -08:00
parent bb2fc21c3b
commit 032ef4bbfc
4 changed files with 64 additions and 13 deletions

View file

@ -715,12 +715,10 @@ func (subst *subster) typ(t *types.Type) *types.Type {
return newsym.Def.Type()
}
// In order to deal with recursive generic types, create a TFORW type
// initially and set its Def field, so it can be found if this type
// appears recursively within the type.
forw = types.New(types.TFORW)
forw.SetSym(newsym)
newsym.Def = ir.TypeNode(forw)
// In order to deal with recursive generic types, create a TFORW
// type initially and set the Def field of its sym, so it can be
// found if this type appears recursively within the type.
forw = newNamedTypeWithSym(t.Pos(), newsym)
//println("Creating new type by sub", newsym.Name, forw.HasTParam())
forw.SetRParams(neededTargs)
}
@ -894,3 +892,13 @@ func deref(t *types.Type) *types.Type {
}
return t
}
// newNamedTypeWithSym returns a TFORW type t with name specified by sym, such
// that t.nod and sym.Def are set correctly.
func newNamedTypeWithSym(pos src.XPos, sym *types.Sym) *types.Type {
name := ir.NewDeclNameAt(pos, ir.OTYPE, sym)
forw := types.NewNamed(name)
name.SetType(forw)
sym.Def = name
return forw
}