diff options
author | Alan Donovan <adonovan@google.com> | 2024-04-24 16:51:20 -0400 |
---|---|---|
committer | Gopher Robot <gobot@golang.org> | 2024-04-24 21:50:16 +0000 |
commit | 9b9de261bd66333885adb7b36f1dd133d00cfe13 (patch) | |
tree | 3b938dd035cb2f3036d066969279d397d556ad6a /src/go/types/api_test.go | |
parent | e689118852c9c1841ee4c17aeeb3ec3a5242e9a2 (diff) | |
download | go-9b9de261bd66333885adb7b36f1dd133d00cfe13.tar.gz go-9b9de261bd66333885adb7b36f1dd133d00cfe13.zip |
go/types: add Alias.Rhs
This method returns the type on the right-hand side of an
alias declaration such as type L = R.
Fixes #66559
Change-Id: I396f2d999680ad251f47cdde20856ae20fc1c40a
Reviewed-on: https://go-review.googlesource.com/c/go/+/581615
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Diffstat (limited to 'src/go/types/api_test.go')
-rw-r--r-- | src/go/types/api_test.go | 18 |
1 files changed, 18 insertions, 0 deletions
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) + } +} |