aboutsummaryrefslogtreecommitdiff
path: root/src/go
diff options
context:
space:
mode:
authorRobert Findley <rfindley@google.com>2021-08-16 14:00:14 -0400
committerRobert Findley <rfindley@google.com>2021-08-16 18:52:20 +0000
commitd35035f84e5dbe4c740d3f338ba89b41a00e270e (patch)
treeac586a34f8bf836fddbc569ee54a4fbeb1940da0 /src/go
parentddffe30a21c909314a7bab8815505b709e921c3c (diff)
downloadgo-d35035f84e5dbe4c740d3f338ba89b41a00e270e.tar.gz
go-d35035f84e5dbe4c740d3f338ba89b41a00e270e.zip
go/types: use the orig object for Named.Obj
This is a port of CL 341858 to go/types. Change-Id: I9fba8941069aaacd641a19e3068de3a769e14e50 Reviewed-on: https://go-review.googlesource.com/c/go/+/342482 Trust: Robert Findley <rfindley@google.com> Run-TryBot: Robert Findley <rfindley@google.com> Reviewed-by: Robert Griesemer <gri@golang.org> TryBot-Result: Go Bot <gobot@golang.org>
Diffstat (limited to 'src/go')
-rw-r--r--src/go/types/named.go9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/go/types/named.go b/src/go/types/named.go
index 1841038fdb..90abd117e2 100644
--- a/src/go/types/named.go
+++ b/src/go/types/named.go
@@ -15,7 +15,7 @@ import (
type Named struct {
check *Checker
info typeInfo // for cycle detection
- obj *TypeName // corresponding declared object
+ obj *TypeName // corresponding declared object for declared types; placeholder for instantiated types
orig *Named // original, uninstantiated type
fromRHS Type // type (on RHS of declaration) this *Named type is derived of (for cycle reporting)
underlying Type // possibly a *Named during setup; never a *Named once set up completely
@@ -108,8 +108,11 @@ func (check *Checker) newNamed(obj *TypeName, orig *Named, underlying Type, tpar
return typ
}
-// Obj returns the type name for the named type t.
-func (t *Named) Obj() *TypeName { return t.obj }
+// Obj returns the type name for the declaration defining the named type t. For
+// instantiated types, this is the type name of the base type.
+func (t *Named) Obj() *TypeName {
+ return t.orig.obj // for non-instances this is the same as t.obj
+}
// _Orig returns the original generic type an instantiated type is derived from.
// If t is not an instantiated type, the result is t.