Description
Proposal Details
Background: Go 1.22's go/types defined new API for materialized alias types, as a step towards generic alias types. Alias has two operations: Underlying
, which removes all Alias and Named constructors, recursively, returning the representation type; and Unalias
, which removes only Alias constructors, again recursively, returning the first non-alias type. (A judicious sprinkling of Unalias
operations throughout existing code is the minimal change to keep most existing go/types clients working.)
However, the API provides no way to remove a single Alias
constructor. That means, for example, that there is no way for a client of go/types, given the types for:
type A = B
type B = int
to write a function that prints "type A = B" (without calling the existing ObjectString
method). More importantly, import/export tools are unable to preserve the structure of the original types.
(Unalias
is nonetheless useful, and Underlying
is of course a requirement of the Type
interface, but Alias types are not isomorphic to defined types in the way that, given type A B; type B int
, the spec defines the underlying type of A as int, and otherwise stipulates no relationship between A and B.)
Proposal: We add an Alias.RHS
accessor method, which removes exactly one Alias
constructor. So, Alias.RHS(A)
would return B.