golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
120.1k stars 17.24k forks source link

go/types: add Alias parameter methods #67143

Closed griesemer closed 1 day ago

griesemer commented 2 weeks ago

For the purposes of generic Alias types we propose the following additional API. As with other generic types, instances are created with types.Instantiate. These methods match the corresponding methods for Named types.

package types

// 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

// SetTypeParams sets the type parameters of the alias type a.
// a must not have type arguments.
func (a *Alias) SetTypeParams(tparams []*TypeParam)

// 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

// 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
gopherbot commented 1 week ago

Change https://go.dev/cl/583757 mentions this issue: go/types, types2: add Alias.{TypeParams, SetTypeParams, TypeArgs, Origin}

rsc commented 1 week ago

These are the same methods that types.Named already has, so this seems fine.

rsc commented 1 week ago

Based on the discussion above, this proposal seems like a likely accept. — rsc for the proposal review group

The proposal is https://github.com/golang/go/issues/67143#issue-2276112912.

rsc commented 1 day ago

No change in consensus, so accepted. 🎉 This issue now tracks the work of implementing the proposal. — rsc for the proposal review group

The proposal is https://github.com/golang/go/issues/67143#issue-2276112912.