]> Cypherpunks repositories - gostls13.git/commitdiff
go/types, types2: coreType/String must consider Alias types
authorRobert Griesemer <gri@golang.org>
Tue, 21 May 2024 22:05:55 +0000 (15:05 -0700)
committerGopher Robot <gobot@golang.org>
Tue, 21 May 2024 22:34:27 +0000 (22:34 +0000)
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>

src/cmd/compile/internal/types2/under.go
src/go/types/under.go
src/internal/types/testdata/fixedbugs/issue67547.go

index 6b24399de43f0ec49d911653991fa55a6586b009..2d90c35d3bacb4a73dd0ead692c147a9c311f532 100644 (file)
@@ -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
index 9f9740e7c34e5809c231f8c0b099e4d3c8c4b9e2..ed5aab238e58573a38fdda480908a41c9d02ad2d 100644 (file)
@@ -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
index cca8ba23672fcdf13402b92cc13087143cc0f474..b95be4faeb22ea38ed2fffd3c1e8eaeb0f131658 100644 (file)
@@ -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
+}