diff --git a/src/cmd/compile/internal/types2/operand.go b/src/cmd/compile/internal/types2/operand.go index 66002aa6c5..a176b9faf3 100644 --- a/src/cmd/compile/internal/types2/operand.go +++ b/src/cmd/compile/internal/types2/operand.go @@ -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. diff --git a/src/go/types/operand.go b/src/go/types/operand.go index fb91e7e612..060a408c26 100644 --- a/src/go/types/operand.go +++ b/src/go/types/operand.go @@ -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. diff --git a/src/internal/types/testdata/fixedbugs/issue67547.go b/src/internal/types/testdata/fixedbugs/issue67547.go index 791d5d5e90..1c2f66b6b9 100644 --- a/src/internal/types/testdata/fixedbugs/issue67547.go +++ b/src/internal/types/testdata/fixedbugs/issue67547.go @@ -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 (