From: Robert Griesemer Date: Tue, 21 May 2024 22:05:55 +0000 (-0700) Subject: go/types, types2: coreType/String must consider Alias types X-Git-Tag: go1.23rc1~236 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=4b778470f834f80aaa84d2066da12889e8ab285f;p=gostls13.git 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 Auto-Submit: Robert Griesemer Reviewed-by: Robert Griesemer LUCI-TryBot-Result: Go LUCI --- diff --git a/src/cmd/compile/internal/types2/under.go b/src/cmd/compile/internal/types2/under.go index 6b24399de4..2d90c35d3b 100644 --- a/src/cmd/compile/internal/types2/under.go +++ b/src/cmd/compile/internal/types2/under.go @@ -22,6 +22,7 @@ func under(t Type) Type { // identical element types), the single underlying type is the restricted // channel type if the restrictions are always the same, or nil otherwise. func coreType(t Type) Type { + t = Unalias(t) tpar, _ := t.(*TypeParam) if tpar == nil { return under(t) @@ -51,6 +52,7 @@ func coreType(t Type) Type { // and strings as identical. In this case, if successful and we saw // a string, the result is of type (possibly untyped) string. func coreString(t Type) Type { + t = Unalias(t) tpar, _ := t.(*TypeParam) if tpar == nil { return under(t) // string or untyped string diff --git a/src/go/types/under.go b/src/go/types/under.go index 9f9740e7c3..ed5aab238e 100644 --- a/src/go/types/under.go +++ b/src/go/types/under.go @@ -25,6 +25,7 @@ func under(t Type) Type { // identical element types), the single underlying type is the restricted // channel type if the restrictions are always the same, or nil otherwise. func coreType(t Type) Type { + t = Unalias(t) tpar, _ := t.(*TypeParam) if tpar == nil { return under(t) @@ -54,6 +55,7 @@ func coreType(t Type) Type { // and strings as identical. In this case, if successful and we saw // a string, the result is of type (possibly untyped) string. func coreString(t Type) Type { + t = Unalias(t) tpar, _ := t.(*TypeParam) if tpar == nil { return under(t) // string or untyped string diff --git a/src/internal/types/testdata/fixedbugs/issue67547.go b/src/internal/types/testdata/fixedbugs/issue67547.go index cca8ba2367..b95be4faeb 100644 --- a/src/internal/types/testdata/fixedbugs/issue67547.go +++ b/src/internal/types/testdata/fixedbugs/issue67547.go @@ -8,3 +8,15 @@ func _[P int]() { type A = P _ = A(0) // don't crash with this conversion } + +func _[P []int]() { + type A = P + _ = make(A, 10) // don't report an error for A +} + +func _[P string]() { + var t []byte + type A = P + var s A + copy(t, s) // don't report an error for s +}