]> Cypherpunks repositories - gostls13.git/commitdiff
go/types, types2: better error message when type argument cannot use operator
authorqiulaidongfeng <2645477756@qq.com>
Tue, 17 Sep 2024 03:59:49 +0000 (11:59 +0800)
committerGopher Robot <gobot@golang.org>
Wed, 18 Sep 2024 14:38:21 +0000 (14:38 +0000)
Fixes #63524

Change-Id: Id33936b9bcfb6a7333c6d084247044bba2f29219
Reviewed-on: https://go-review.googlesource.com/c/go/+/613756
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
src/cmd/compile/internal/types2/expr.go
src/go/types/expr.go
src/internal/types/testdata/check/typeparams.go
src/internal/types/testdata/fixedbugs/issue48712.go
src/internal/types/testdata/spec/comparisons.go

index 72f0efbfdef275786a0b3dd20d0ded8f97ec8259..96f05ddb114a6f3db988eebd7cf1e5724dd918f1 100644 (file)
@@ -574,7 +574,7 @@ Error:
                        if !isTypeParam(x.typ) {
                                errOp = y
                        }
-                       cause = check.sprintf("type parameter %s is not comparable with %s", errOp.typ, op)
+                       cause = check.sprintf("type parameter %s cannot use operator %s", errOp.typ, op)
                } else {
                        cause = check.sprintf("operator %s not defined on %s", op, check.kindString(errOp.typ)) // catch-all
                }
index 4f17ebbc4fdeed1fc875de9c65ce30bf381a98ed..d918059f77d3a9ded99820bbf53ef2a8772e0896 100644 (file)
@@ -565,7 +565,7 @@ Error:
                        if !isTypeParam(x.typ) {
                                errOp = y
                        }
-                       cause = check.sprintf("type parameter %s is not comparable with %s", errOp.typ, op)
+                       cause = check.sprintf("type parameter %s cannot use operator %s", errOp.typ, op)
                } else {
                        cause = check.sprintf("operator %s not defined on %s", op, check.kindString(errOp.typ)) // catch-all
                }
index b002377df79e02b054cce0387067fb6d9a8d8465..5fd82a5aa079e7cef74a7c076148d3b6b1adec68 100644 (file)
@@ -58,10 +58,10 @@ func min[T interface{ ~int }](x, y T) T {
 }
 
 func _[T interface{~int | ~float32}](x, y T) bool { return x < y }
-func _[T any](x, y T) bool { return x /* ERROR "type parameter T is not comparable" */ < y }
-func _[T interface{~int | ~float32 | ~bool}](x, y T) bool { return x /* ERROR "type parameter T is not comparable" */ < y }
+func _[T any](x, y T) bool { return x /* ERROR "type parameter T cannot use operator <" */ < y }
+func _[T interface{~int | ~float32 | ~bool}](x, y T) bool { return x /* ERROR "type parameter T cannot use operator <" */ < y }
 
-func _[T C1[T]](x, y T) bool { return x /* ERROR "type parameter T is not comparable" */ < y }
+func _[T C1[T]](x, y T) bool { return x /* ERROR "type parameter T cannot use operator <" */ < y }
 func _[T C2[T]](x, y T) bool { return x < y }
 
 type C1[T any] interface{}
index 76ad16cd8feea906c6019cb3786c5b8a89a38b51..028660fb1e30bcea50298442ec2a658b137c8eb7 100644 (file)
@@ -10,7 +10,7 @@ func _[P comparable](x, y P) {
        _ = y == x
        _ = y == y
 
-       _ = x /* ERROR "type parameter P is not comparable with <" */ < y
+       _ = x /* ERROR "type parameter P cannot use operator <" */ < y
 }
 
 func _[P comparable](x P, y any) {
@@ -19,7 +19,7 @@ func _[P comparable](x P, y any) {
        _ = y == x
        _ = y == y
 
-       _ = x /* ERROR "type parameter P is not comparable with <" */ < y
+       _ = x /* ERROR "type parameter P cannot use operator <" */ < y
 }
 
 func _[P any](x, y P) {
@@ -28,7 +28,7 @@ func _[P any](x, y P) {
        _ = y /* ERROR "incomparable types in type set" */ == x
        _ = y /* ERROR "incomparable types in type set" */ == y
 
-       _ = x /* ERROR "type parameter P is not comparable with <" */ < y
+       _ = x /* ERROR "type parameter P cannot use operator <" */ < y
 }
 
 func _[P any](x P, y any) {
@@ -37,5 +37,5 @@ func _[P any](x P, y any) {
        _ = y == x // ERROR "incomparable types in type set"
        _ = y == y
 
-       _ = x /* ERROR "type parameter P is not comparable with <" */ < y
+       _ = x /* ERROR "type parameter P cannot use operator <" */ < y
 }
index 492890e49e9734a9f324deb9b172a560254bb8a0..dd92d99b1b57b7eaf2686b1ad419b9bb8b7c4468 100644 (file)
@@ -108,13 +108,13 @@ func _[
        _ = c == nil
 
        _ = b < b
-       _ = a /* ERROR "type parameter A is not comparable with <" */ < a
-       _ = l /* ERROR "type parameter L is not comparable with <" */ < l
-       _ = s /* ERROR "type parameter S is not comparable with <" */ < s
-       _ = p /* ERROR "type parameter P is not comparable with <" */ < p
-       _ = f /* ERROR "type parameter F is not comparable with <" */ < f
-       _ = i /* ERROR "type parameter I is not comparable with <" */ < i
-       _ = j /* ERROR "type parameter J is not comparable with <" */ < j
-       _ = m /* ERROR "type parameter M is not comparable with <" */ < m
-       _ = c /* ERROR "type parameter C is not comparable with <" */ < c
+       _ = a /* ERROR "type parameter A cannot use operator <" */ < a
+       _ = l /* ERROR "type parameter L cannot use operator <" */ < l
+       _ = s /* ERROR "type parameter S cannot use operator <" */ < s
+       _ = p /* ERROR "type parameter P cannot use operator <" */ < p
+       _ = f /* ERROR "type parameter F cannot use operator <" */ < f
+       _ = i /* ERROR "type parameter I cannot use operator <" */ < i
+       _ = j /* ERROR "type parameter J cannot use operator <" */ < j
+       _ = m /* ERROR "type parameter M cannot use operator <" */ < m
+       _ = c /* ERROR "type parameter C cannot use operator <" */ < c
 }