Fixes #67143.
Change-Id: I8bf9c2559f95d3d6a40874454208ae074b68875c
Reviewed-on: https://go-review.googlesource.com/c/go/+/583757
Reviewed-by: Alan Donovan <adonovan@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
--- /dev/null
+pkg go/types, method (*Alias) Origin() *Alias #67143
+pkg go/types, method (*Alias) SetTypeParams([]*TypeParam) #67143
+pkg go/types, method (*Alias) TypeArgs() *TypeList #67143
+pkg go/types, method (*Alias) TypeParams() *TypeParamList #67143
--- /dev/null
+The methods [Alias.Origin], [Alias.SetTypeParams], [Alias.TypeParams],
+and [Alias.TypeArgs] have been added. They are needed for generic alias types.
// which points directly to the actual (aliased) type.
type Alias struct {
obj *TypeName // corresponding declared alias object
+ orig *Alias // original, uninstantiated alias
tparams *TypeParamList // type parameters, or nil
+ targs *TypeList // type arguments, or nil
fromRHS Type // RHS of type alias declaration; may be an alias
actual Type // actual (aliased) type; never an alias
}
// [underlying type]: https://go.dev/ref/spec#Underlying_types.
func (a *Alias) Underlying() Type { return unalias(a).Underlying() }
+// Origin returns the generic Alias type of which a is an instance.
+// If a is not an instance of a generic alias, Origin returns a.
+func (a *Alias) Origin() *Alias { return a.orig }
+
+// TypeParams returns the type parameters of the alias type a, or nil.
+// A generic Alias and its instances have the same type parameters.
+func (a *Alias) TypeParams() *TypeParamList { return a.tparams }
+
+// SetTypeParams sets the type parameters of the alias type a.
+// The alias a must not have type arguments.
+func (a *Alias) SetTypeParams(tparams []*TypeParam) {
+ assert(a.targs == nil)
+ a.tparams = bindTParams(tparams)
+}
+
+// TypeArgs returns the type arguments used to instantiate the Alias type.
+// If a is not an instance of a generic alias, the result is nil.
+func (a *Alias) TypeArgs() *TypeList { return a.targs }
+
// Rhs returns the type R on the right-hand side of an alias
// declaration "type A = R", which may be another alias.
func (a *Alias) Rhs() Type { return a.fromRHS }
// rhs must not be nil.
func (check *Checker) newAlias(obj *TypeName, rhs Type) *Alias {
assert(rhs != nil)
- a := &Alias{obj, nil, rhs, nil}
+ a := new(Alias)
+ a.obj = obj
+ a.orig = a
+ a.fromRHS = rhs
if obj.typ == nil {
obj.typ = a
}
// which points directly to the actual (aliased) type.
type Alias struct {
obj *TypeName // corresponding declared alias object
+ orig *Alias // original, uninstantiated alias
tparams *TypeParamList // type parameters, or nil
+ targs *TypeList // type arguments, or nil
fromRHS Type // RHS of type alias declaration; may be an alias
actual Type // actual (aliased) type; never an alias
}
// [underlying type]: https://go.dev/ref/spec#Underlying_types.
func (a *Alias) Underlying() Type { return unalias(a).Underlying() }
+// Origin returns the generic Alias type of which a is an instance.
+// If a is not an instance of a generic alias, Origin returns a.
+func (a *Alias) Origin() *Alias { return a.orig }
+
+// TypeParams returns the type parameters of the alias type a, or nil.
+// A generic Alias and its instances have the same type parameters.
+func (a *Alias) TypeParams() *TypeParamList { return a.tparams }
+
+// SetTypeParams sets the type parameters of the alias type a.
+// The alias a must not have type arguments.
+func (a *Alias) SetTypeParams(tparams []*TypeParam) {
+ assert(a.targs == nil)
+ a.tparams = bindTParams(tparams)
+}
+
+// TypeArgs returns the type arguments used to instantiate the Alias type.
+// If a is not an instance of a generic alias, the result is nil.
+func (a *Alias) TypeArgs() *TypeList { return a.targs }
+
// Rhs returns the type R on the right-hand side of an alias
// declaration "type A = R", which may be another alias.
func (a *Alias) Rhs() Type { return a.fromRHS }
// rhs must not be nil.
func (check *Checker) newAlias(obj *TypeName, rhs Type) *Alias {
assert(rhs != nil)
- a := &Alias{obj, nil, rhs, nil}
+ a := new(Alias)
+ a.obj = obj
+ a.orig = a
+ a.fromRHS = rhs
if obj.typ == nil {
obj.typ = a
}