mirror of
https://github.com/golang/go.git
synced 2025-05-18 22:04:38 +00: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:
parent
750738b5d1
commit
ccb6077d11
@ -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 {
|
||||
|
@ -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 {
|
||||
|
13
src/internal/types/testdata/fixedbugs/issue65854.go
vendored
Normal file
13
src/internal/types/testdata/fixedbugs/issue65854.go
vendored
Normal 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]
|
Loading…
x
Reference in New Issue
Block a user