diff options
Diffstat (limited to 'src/go/types')
-rw-r--r-- | src/go/types/alias.go | 8 | ||||
-rw-r--r-- | src/go/types/api_test.go | 18 |
2 files changed, 21 insertions, 5 deletions
diff --git a/src/go/types/alias.go b/src/go/types/alias.go index 963eb92d35..56d2ad0c97 100644 --- a/src/go/types/alias.go +++ b/src/go/types/alias.go @@ -35,11 +35,9 @@ func (a *Alias) Obj() *TypeName { return a.obj } func (a *Alias) Underlying() Type { return unalias(a).Underlying() } func (a *Alias) String() string { return TypeString(a, nil) } -// TODO(adonovan): uncomment when proposal #66559 is accepted. -// -// // 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 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 } // Unalias returns t if it is not an alias type; // otherwise it follows t's alias chain until it diff --git a/src/go/types/api_test.go b/src/go/types/api_test.go index 564bbc2423..6f8dddb936 100644 --- a/src/go/types/api_test.go +++ b/src/go/types/api_test.go @@ -3014,3 +3014,21 @@ type B = T[A] t.Errorf("Unalias(type B = T[A]) = %q, want %q", got, want) } } + +func TestAlias_Rhs(t *testing.T) { + t.Setenv("GODEBUG", "gotypesalias=1") + const src = `package p + +type A = B +type B = C +type C = int +` + + pkg := mustTypecheck(src, nil, nil) + A := pkg.Scope().Lookup("A") + + got, want := A.Type().(*Alias).Rhs().String(), "p.B" + if got != want { + t.Errorf("A.Rhs = %s, want %s", got, want) + } +} |