aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd/compile')
-rw-r--r--src/cmd/compile/internal/types2/alias.go8
-rw-r--r--src/cmd/compile/internal/types2/api.go7
-rw-r--r--src/cmd/compile/internal/types2/api_test.go17
3 files changed, 20 insertions, 12 deletions
diff --git a/src/cmd/compile/internal/types2/alias.go b/src/cmd/compile/internal/types2/alias.go
index 030f6cd827..9b7a13f81e 100644
--- a/src/cmd/compile/internal/types2/alias.go
+++ b/src/cmd/compile/internal/types2/alias.go
@@ -32,11 +32,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/cmd/compile/internal/types2/api.go b/src/cmd/compile/internal/types2/api.go
index 36d900401d..029d105e2e 100644
--- a/src/cmd/compile/internal/types2/api.go
+++ b/src/cmd/compile/internal/types2/api.go
@@ -475,10 +475,3 @@ func (conf *Config) Check(path string, files []*syntax.File, info *Info) (*Packa
pkg := NewPackage(path, "")
return pkg, NewChecker(conf, pkg, info).Files(files)
}
-
-// Rhs returns the type R on the right-hand side of an alias
-// declaration "type A = R", which may be another alias.
-//
-// TODO(adonovan): move to alias.go (common with go/types) once
-// proposal #66559 is accepted.
-func (a *Alias) Rhs() Type { return a.fromRHS }
diff --git a/src/cmd/compile/internal/types2/api_test.go b/src/cmd/compile/internal/types2/api_test.go
index 840a3f3bdc..cf3c105f6c 100644
--- a/src/cmd/compile/internal/types2/api_test.go
+++ b/src/cmd/compile/internal/types2/api_test.go
@@ -3005,3 +3005,20 @@ type B = T[A]
t.Errorf("Unalias(type B = T[A]) = %q, want %q", got, want)
}
}
+
+func TestAlias_Rhs(t *testing.T) {
+ const src = `package p
+
+type A = B
+type B = C
+type C = int
+`
+
+ pkg := mustTypecheck(src, &Config{EnableAlias: true}, 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)
+ }
+}