Skip to content

Commit 4b77847

Browse files
griesemergopherbot
authored andcommitted
go/types, types2: coreType/String must consider Alias types
Fixes regression from Go 1.22. For #67547. Change-Id: Idd319b9d2a73c824caa2c821df0e2fcd4f58cb08 Reviewed-on: https://go-review.googlesource.com/c/go/+/587176 Reviewed-by: Robert Findley <rfindley@google.com> Auto-Submit: Robert Griesemer <gri@google.com> Reviewed-by: Robert Griesemer <gri@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
1 parent 814e72f commit 4b77847

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

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

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ func under(t Type) Type {
2222
// identical element types), the single underlying type is the restricted
2323
// channel type if the restrictions are always the same, or nil otherwise.
2424
func coreType(t Type) Type {
25+
t = Unalias(t)
2526
tpar, _ := t.(*TypeParam)
2627
if tpar == nil {
2728
return under(t)
@@ -51,6 +52,7 @@ func coreType(t Type) Type {
5152
// and strings as identical. In this case, if successful and we saw
5253
// a string, the result is of type (possibly untyped) string.
5354
func coreString(t Type) Type {
55+
t = Unalias(t)
5456
tpar, _ := t.(*TypeParam)
5557
if tpar == nil {
5658
return under(t) // string or untyped string

src/go/types/under.go

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/internal/types/testdata/fixedbugs/issue67547.go

+12
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,15 @@ func _[P int]() {
88
type A = P
99
_ = A(0) // don't crash with this conversion
1010
}
11+
12+
func _[P []int]() {
13+
type A = P
14+
_ = make(A, 10) // don't report an error for A
15+
}
16+
17+
func _[P string]() {
18+
var t []byte
19+
type A = P
20+
var s A
21+
copy(t, s) // don't report an error for s
22+
}

0 commit comments

Comments
 (0)