aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/types2
diff options
context:
space:
mode:
authorRob Findley <rfindley@google.com>2021-08-11 12:43:27 -0400
committerRobert Findley <rfindley@google.com>2021-08-14 15:14:57 +0000
commit456759b24682a41e282f73855377ac4f341da191 (patch)
tree15c9b594e0578907a956b9515cc6620c6b74eb79 /src/cmd/compile/internal/types2
parent2d250043b4c5095f326ab72741d557fe74e4e3a6 (diff)
downloadgo-456759b24682a41e282f73855377ac4f341da191.tar.gz
go-456759b24682a41e282f73855377ac4f341da191.zip
cmd/compile/internal/types2: use the orig object for Named.Obj
Exposing a synthetic type name for instantiated types is problematic: there is no way to ensure that type instances are first created in the same type checking pass, and therefore no guarantee that their instantiation positions are the same. Even type checking a given package with different file ordering could result in different positions being associated with type instances. This is therefore an implementation detail that we should not expose. Keep the synthetic type name for accurate error reporting, but hide it in the API. Change-Id: I61f0e3ed322e97b157eb1ca316480f5719dcc174 Reviewed-on: https://go-review.googlesource.com/c/go/+/341858 Trust: Robert Findley <rfindley@google.com> Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
Diffstat (limited to 'src/cmd/compile/internal/types2')
-rw-r--r--src/cmd/compile/internal/types2/named.go9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/cmd/compile/internal/types2/named.go b/src/cmd/compile/internal/types2/named.go
index 5967172675..ad29886f7d 100644
--- a/src/cmd/compile/internal/types2/named.go
+++ b/src/cmd/compile/internal/types2/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 from (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.