Skip to content

Commit ccb6077

Browse files
griesemergopherbot
authored andcommitted
go/types, types2: handle Alias types in substitution
Fixes #65854. For #65778. // for x/tools/cmd/gotype Change-Id: I67d4644b28e831926fc6c233098aa1755c57162f Reviewed-on: https://go-review.googlesource.com/c/go/+/565835 Auto-Submit: Robert Griesemer <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Robert Findley <[email protected]> Reviewed-by: Robert Griesemer <[email protected]>
1 parent 750738b commit ccb6077

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

src/cmd/compile/internal/types2/subst.go

+12
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,18 @@ func (subst *subster) typ(typ Type) Type {
9595
case *Basic:
9696
// nothing to do
9797

98+
case *Alias:
99+
rhs := subst.typ(t.fromRHS)
100+
if rhs != t.fromRHS {
101+
// This branch cannot be reached because the RHS of an alias
102+
// may only contain type parameters of an enclosing function.
103+
// Such function bodies are never "instantiated" and thus
104+
// substitution is not called on locally declared alias types.
105+
// TODO(gri) adjust once parameterized aliases are supported
106+
panic("unreachable for unparameterized aliases")
107+
// return subst.check.newAlias(t.obj, rhs)
108+
}
109+
98110
case *Array:
99111
elem := subst.typOrNil(t.elem)
100112
if elem != t.elem {

src/go/types/subst.go

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// -gotypesalias=1
2+
3+
// Copyright 2024 The Go Authors. All rights reserved.
4+
// Use of this source code is governed by a BSD-style
5+
// license that can be found in the LICENSE file.
6+
7+
package p
8+
9+
type A = int
10+
11+
type T[P any] *A
12+
13+
var _ T[int]

0 commit comments

Comments
 (0)