Skip to content

Commit

Permalink
[release-branch.go1.22] go/types, types2: handle Alias types in subst…
Browse files Browse the repository at this point in the history
…itution

Fixes #65858.
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>
Reviewed-on: https://go-review.googlesource.com/c/go/+/565840
Run-TryBot: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
  • Loading branch information
griesemer authored and thanm committed Mar 26, 2024
1 parent 3826650 commit e23707b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/cmd/compile/internal/types2/subst.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 12 additions & 0 deletions src/go/types/subst.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions src/internal/types/testdata/fixedbugs/issue65854.go
Original file line number Diff line number Diff line change
@@ -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]

0 comments on commit e23707b

Please # to comment.