aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/noder/stencil.go
diff options
context:
space:
mode:
authorDan Scales <danscales@google.com>2021-03-10 15:25:21 -0800
committerDan Scales <danscales@google.com>2021-03-30 04:48:27 +0000
commit032ef4bbfc5b976085c561eb4a134b780625f410 (patch)
treef227b8a1a6b63259d31bb3e4bd3cfae7e5080eaf /src/cmd/compile/internal/noder/stencil.go
parentbb2fc21c3b818c45fad23fdf5f8bd83bbc074dce (diff)
downloadgo-032ef4bbfc5b976085c561eb4a134b780625f410.tar.xz
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>
Diffstat (limited to 'src/cmd/compile/internal/noder/stencil.go')
-rw-r--r--src/cmd/compile/internal/noder/stencil.go20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/cmd/compile/internal/noder/stencil.go b/src/cmd/compile/internal/noder/stencil.go
index 8dcc9d811e..78e701eaf8 100644
--- a/src/cmd/compile/internal/noder/stencil.go
+++ b/src/cmd/compile/internal/noder/stencil.go
@@ -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
+}