Skip to content

Commit 13e3068

Browse files
griesemerRobert Griesemer
authored and
Robert Griesemer
committed
go/types, types2: add missing Unalias call to type string functionality
For #67547. Change-Id: I999cd31f9a01f91e7984b4e7012c81e8bd9c6b06 Reviewed-on: https://go-review.googlesource.com/c/go/+/587940 Reviewed-by: Robert Griesemer <[email protected]> Auto-Submit: Robert Griesemer <[email protected]> Reviewed-by: Robert Findley <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent acc93da commit 13e3068

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ func operandString(x *operand, qf Qualifier) string {
186186
}
187187
buf.WriteString(intro)
188188
WriteType(&buf, x.typ, qf)
189-
if tpar, _ := x.typ.(*TypeParam); tpar != nil {
189+
if tpar, _ := Unalias(x.typ).(*TypeParam); tpar != nil {
190190
buf.WriteString(" constrained by ")
191191
WriteType(&buf, tpar.bound, qf) // do not compute interface type sets here
192192
// If we have the type set and it's empty, say so for better error messages.

src/go/types/operand.go

Lines changed: 1 addition & 1 deletion
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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@ func _[P []int | struct{}]() {
7777
_ = a
7878
}
7979

80+
func _[P any]() {
81+
type A = P
82+
var x A
83+
// keep "constrained by" for aliased type parameters in error messages
84+
var _ int = x // ERRORx `cannot use x \(variable of type (A|P) constrained by any\) as int value in variable declaration`
85+
}
86+
8087
// Test case for go.dev/issue/67540.
8188
func _() {
8289
type (

0 commit comments

Comments
 (0)