]> Cypherpunks repositories - gostls13.git/commitdiff
go/types, types2: add missing Unalias call to type string functionality
authorRobert Griesemer <gri@golang.org>
Thu, 23 May 2024 20:54:17 +0000 (13:54 -0700)
committerRobert Griesemer <gri@google.com>
Thu, 23 May 2024 21:17:10 +0000 (21:17 +0000)
For #67547.

Change-Id: I999cd31f9a01f91e7984b4e7012c81e8bd9c6b06
Reviewed-on: https://go-review.googlesource.com/c/go/+/587940
Reviewed-by: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

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

index 66002aa6c5d1468fad8ee524b2ee0a73bfe7a66f..a176b9faf36a3286c540426941b1599c963cf5f9 100644 (file)
@@ -186,7 +186,7 @@ func operandString(x *operand, qf Qualifier) string {
                        }
                        buf.WriteString(intro)
                        WriteType(&buf, x.typ, qf)
-                       if tpar, _ := x.typ.(*TypeParam); tpar != nil {
+                       if tpar, _ := Unalias(x.typ).(*TypeParam); tpar != nil {
                                buf.WriteString(" constrained by ")
                                WriteType(&buf, tpar.bound, qf) // do not compute interface type sets here
                                // If we have the type set and it's empty, say so for better error messages.
index fb91e7e61284442d038cda1ded056279db3c7428..060a408c264140b21667af593e9b1ec19c8ef0a2 100644 (file)
@@ -190,7 +190,7 @@ func operandString(x *operand, qf Qualifier) string {
                        }
                        buf.WriteString(intro)
                        WriteType(&buf, x.typ, qf)
-                       if tpar, _ := x.typ.(*TypeParam); tpar != nil {
+                       if tpar, _ := Unalias(x.typ).(*TypeParam); tpar != nil {
                                buf.WriteString(" constrained by ")
                                WriteType(&buf, tpar.bound, qf) // do not compute interface type sets here
                                // If we have the type set and it's empty, say so for better error messages.
index 791d5d5e90dee687a6fe1dc3887bcc1b79eb766b..1c2f66b6b99172a791ca80d1a143643acc64595a 100644 (file)
@@ -77,6 +77,13 @@ func _[P []int | struct{}]() {
        _ = a
 }
 
+func _[P any]() {
+       type A = P
+       var x A
+       // keep "constrained by" for aliased type parameters in error messages
+       var _ int = x // ERRORx `cannot use x \(variable of type (A|P) constrained by any\) as int value in variable declaration`
+}
+
 // Test case for go.dev/issue/67540.
 func _() {
        type (