diff --git a/src/cmd/compile/internal/types2/subst.go b/src/cmd/compile/internal/types2/subst.go index 09dc58527a11f1..1ad73c41ce1f08 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 1934ebab2b1a4f..178f7172835894 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 00000000000000..744777a94f8457 --- /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]