aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/types/type.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/types/type.go
parentbb2fc21c3b818c45fad23fdf5f8bd83bbc074dce (diff)
downloadgo-032ef4bbfc5b976085c561eb4a134b780625f410.tar.gz
go-032ef4bbfc5b976085c561eb4a134b780625f410.zip
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/types/type.go')
-rw-r--r--src/cmd/compile/internal/types/type.go9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/cmd/compile/internal/types/type.go b/src/cmd/compile/internal/types/type.go
index 7bf63764b8..31a99781d1 100644
--- a/src/cmd/compile/internal/types/type.go
+++ b/src/cmd/compile/internal/types/type.go
@@ -160,8 +160,9 @@ type Type struct {
methods Fields
allMethods Fields
- nod Object // canonical OTYPE node
- underlying *Type // original type (type literal or predefined type)
+ // canonical OTYPE node for a named type (should be an ir.Name node with same sym)
+ nod Object
+ underlying *Type // original type (type literal or predefined type)
// Cache of composite types, with this type being the element type.
cache struct {
@@ -1642,7 +1643,7 @@ var (
TypeResultMem = newResults([]*Type{TypeMem})
)
-// NewNamed returns a new named type for the given type name.
+// NewNamed returns a new named type for the given type name. obj should be an ir.Name.
func NewNamed(obj Object) *Type {
t := New(TFORW)
t.sym = obj.Sym()
@@ -1650,7 +1651,7 @@ func NewNamed(obj Object) *Type {
return t
}
-// Obj returns the type name for the named type t.
+// Obj returns the canonical type name node for a named type t, nil for an unnamed type.
func (t *Type) Obj() Object {
if t.sym != nil {
return t.nod