1
0
mirror of https://github.com/golang/go synced 2024-11-17 11:44:51 -07:00

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>
This commit is contained in:
Robert Findley 2021-08-16 14:00:14 -04:00
parent ddffe30a21
commit d35035f84e

View File

@ -15,7 +15,7 @@ import (
type Named struct { type Named struct {
check *Checker check *Checker
info typeInfo // for cycle detection 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 orig *Named // original, uninstantiated type
fromRHS Type // type (on RHS of declaration) this *Named type is derived of (for cycle reporting) 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 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 return typ
} }
// Obj returns the type name for the named type t. // Obj returns the type name for the declaration defining the named type t. For
func (t *Named) Obj() *TypeName { return t.obj } // 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. // _Orig returns the original generic type an instantiated type is derived from.
// If t is not an instantiated type, the result is t. // If t is not an instantiated type, the result is t.