aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/cmd/compile/internal/types2/subst.go12
-rw-r--r--src/go/types/subst.go12
-rw-r--r--src/internal/types/testdata/fixedbugs/issue65854.go13
3 files changed, 37 insertions, 0 deletions
diff --git a/src/cmd/compile/internal/types2/subst.go b/src/cmd/compile/internal/types2/subst.go
index 09dc58527a..1ad73c41ce 100644
--- a/src/cmd/compile/internal/types2/subst.go
+++ b/src/cmd/compile/internal/types2/subst.go
@@ -95,6 +95,18 @@ func (subst *subster) typ(typ Type) Type {
case *Basic:
// nothing to do
+ case *Alias:
+ rhs := subst.typ(t.fromRHS)
+ if rhs != t.fromRHS {
+ // This branch cannot be reached because the RHS of an alias
+ // may only contain type parameters of an enclosing function.
+ // Such function bodies are never "instantiated" and thus
+ // substitution is not called on locally declared alias types.
+ // TODO(gri) adjust once parameterized aliases are supported
+ panic("unreachable for unparameterized aliases")
+ // return subst.check.newAlias(t.obj, rhs)
+ }
+
case *Array:
elem := subst.typOrNil(t.elem)
if elem != t.elem {
diff --git a/src/go/types/subst.go b/src/go/types/subst.go
index 1934ebab2b..178f717283 100644
--- a/src/go/types/subst.go
+++ b/src/go/types/subst.go
@@ -97,6 +97,18 @@ func (subst *subster) typ(typ Type) Type {
case *Basic:
// nothing to do
+ case *Alias:
+ rhs := subst.typ(t.fromRHS)
+ if rhs != t.fromRHS {
+ // This branch cannot be reached because the RHS of an alias
+ // may only contain type parameters of an enclosing function.
+ // Such function bodies are never "instantiated" and thus
+ // substitution is not called on locally declared alias types.
+ // TODO(gri) adjust once parameterized aliases are supported
+ panic("unreachable for unparameterized aliases")
+ // return subst.check.newAlias(t.obj, rhs)
+ }
+
case *Array:
elem := subst.typOrNil(t.elem)
if elem != t.elem {
diff --git a/src/internal/types/testdata/fixedbugs/issue65854.go b/src/internal/types/testdata/fixedbugs/issue65854.go
new file mode 100644
index 0000000000..744777a94f
--- /dev/null
+++ b/src/internal/types/testdata/fixedbugs/issue65854.go
@@ -0,0 +1,13 @@
+// -gotypesalias=1
+
+// Copyright 2024 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package p
+
+type A = int
+
+type T[P any] *A
+
+var _ T[int]