1
0
mirror of https://github.com/golang/go synced 2024-09-29 07:24:32 -06:00

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 <gri@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
This commit is contained in:
Robert Griesemer 2024-02-21 12:54:10 -08:00 committed by Gopher Robot
parent 750738b5d1
commit ccb6077d11
3 changed files with 37 additions and 0 deletions

View File

@ -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 {

View File

@ -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 {

View File

@ -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]