For #51525.
Change-Id: I3762bc4a48a1aaab3b006b1ad1400f866892243c
Reviewed-on: https://go-review.googlesource.com/c/go/+/413934
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Robert Griesemer <gri@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
}
return true
case *Interface:
- return dynamic && !isTypeParam(T) || t.typeSet().IsComparable(seen)
+ if dynamic && !isTypeParam(T) || t.typeSet().IsComparable(seen) {
+ return true
+ }
+ if reportf != nil {
+ if t.typeSet().IsEmpty() {
+ reportf("empty type set")
+ } else {
+ reportf("incomparable types in type set")
+ }
+ }
+ // fallthrough
}
return false
}
}
func _[P any](x, y P) {
- _ = x /* ERROR type parameter P is not comparable with == */ == x
- _ = x /* ERROR type parameter P is not comparable with == */ == y
- _ = y /* ERROR type parameter P is not comparable with == */ == x
- _ = y /* ERROR type parameter P is not comparable with == */ == y
+ _ = x /* ERROR incomparable types in type set */ == x
+ _ = x /* ERROR incomparable types in type set */ == y
+ _ = 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
}
func _[P any](x P, y any) {
- _ = x /* ERROR type parameter P is not comparable with == */ == x
- _ = x /* ERROR type parameter P is not comparable with == */ == y
- _ = y == x // ERROR type parameter P is not comparable with ==
+ _ = x /* ERROR incomparable types in type set */ == x
+ _ = x /* ERROR incomparable types in type set */ == y
+ _ = y == x // ERROR incomparable types in type set
_ = y == y
_ = x /* ERROR type parameter P is not comparable with < */ < y
--- /dev/null
+// Copyright 2022 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package p
+
+func _[T interface {
+ int
+ string
+}](x T) {
+ _ = x /* ERROR empty type set */ == x
+}
+
+func _[T interface{ int | []byte }](x T) {
+ _ = x /* ERROR incomparable types in type set */ == x
+}
_ = m /* ERROR map can only be compared to nil */ == m
_ = c == c
- _ = b /* ERROR mismatched types */ == nil
+ _ = b /* ERROR mismatched types */ == nil
_ = a /* ERROR mismatched types */ == nil
_ = l == nil
_ = s /* ERROR mismatched types */ == nil
J comparable,
M map[string]int,
C chan int,
-] (
+](
b B,
a A,
l L,
c C,
) {
_ = 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
+ _ = a /* ERROR incomparable types in type set */ == a
+ _ = l /* ERROR incomparable types in type set */ == l
+ _ = s /* ERROR incomparable types in type set */ == s
_ = p == p
- _ = f /* ERROR type parameter F is not comparable with == */ == f
- _ = i /* ERROR type parameter I is not comparable with == */ == i
+ _ = f /* ERROR incomparable types in type set */ == f
+ _ = i /* ERROR incomparable types in type set */ == i
_ = j == j
- _ = m /* ERROR type parameter M is not comparable with == */ == m
+ _ = m /* ERROR incomparable types in type set */ == m
_ = c == c
_ = b /* ERROR mismatched types */ == nil
}
return true
case *Interface:
- return dynamic && !isTypeParam(T) || t.typeSet().IsComparable(seen)
+ if dynamic && !isTypeParam(T) || t.typeSet().IsComparable(seen) {
+ return true
+ }
+ if reportf != nil {
+ if t.typeSet().IsEmpty() {
+ reportf("empty type set")
+ } else {
+ reportf("incomparable types in type set")
+ }
+ }
+ // fallthrough
}
return false
}
}
func _[P any](x, y P) {
- _ = x /* ERROR type parameter P is not comparable with == */ == x
- _ = x /* ERROR type parameter P is not comparable with == */ == y
- _ = y /* ERROR type parameter P is not comparable with == */ == x
- _ = y /* ERROR type parameter P is not comparable with == */ == y
+ _ = x /* ERROR incomparable types in type set */ == x
+ _ = x /* ERROR incomparable types in type set */ == y
+ _ = 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
}
func _[P any](x P, y any) {
- _ = x /* ERROR type parameter P is not comparable with == */ == x
- _ = x /* ERROR type parameter P is not comparable with == */ == y
- _ = y == x // ERROR type parameter P is not comparable with ==
+ _ = x /* ERROR incomparable types in type set */ == x
+ _ = x /* ERROR incomparable types in type set */ == y
+ _ = y == x // ERROR incomparable types in type set
_ = y == y
_ = x /* ERROR type parameter P is not comparable with < */ < y
--- /dev/null
+// Copyright 2022 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package p
+
+func _[T interface {
+ int
+ string
+}](x T) {
+ _ = x /* ERROR empty type set */ == x
+}
+
+func _[T interface{ int | []byte }](x T) {
+ _ = x /* ERROR incomparable types in type set */ == x
+}
_ = m /* ERROR map can only be compared to nil */ == m
_ = c == c
- _ = b /* ERROR mismatched types */ == nil
+ _ = b /* ERROR mismatched types */ == nil
_ = a /* ERROR mismatched types */ == nil
_ = l == nil
_ = s /* ERROR mismatched types */ == nil
J comparable,
M map[string]int,
C chan int,
-] (
+](
b B,
a A,
l L,
c C,
) {
_ = 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
+ _ = a /* ERROR incomparable types in type set */ == a
+ _ = l /* ERROR incomparable types in type set */ == l
+ _ = s /* ERROR incomparable types in type set */ == s
_ = p == p
- _ = f /* ERROR type parameter F is not comparable with == */ == f
- _ = i /* ERROR type parameter I is not comparable with == */ == i
+ _ = f /* ERROR incomparable types in type set */ == f
+ _ = i /* ERROR incomparable types in type set */ == i
_ = j == j
- _ = m /* ERROR type parameter M is not comparable with == */ == m
+ _ = m /* ERROR incomparable types in type set */ == m
_ = c == c
_ = b /* ERROR mismatched types */ == nil