3 // Copyright 2010 The Go Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file.
7 // Verify that incorrect comparisons are detected.
17 type T3 struct{ z []int }
29 // Arguments to comparison must be
30 // assignable one to the other (or vice versa)
31 // so chan int can be compared against
32 // directional channels but channel of different
33 // direction cannot be compared against each other.
38 use(c1 == c2) // ERROR "invalid operation|incompatible"
39 use(c2 == c1) // ERROR "invalid operation|incompatible"
45 // Same applies to named types.
50 use(p1 == p2) // ERROR "invalid operation|incompatible"
51 use(p2 == p1) // ERROR "invalid operation|incompatible"
57 // Arrays are comparable if and only if their element type is comparable.
62 use(a2 == a2) // ERROR "invalid operation|invalid comparison"
63 use(a3 == a3) // ERROR "invalid operation|invalid comparison"
65 // Comparison of structs should have a good message
66 use(t3 == t3) // ERROR "struct|expected|cannot compare"
67 use(t4 == t4) // ERROR "cannot be compared|non-comparable|cannot compare"
69 // Slices, functions, and maps too.
73 use(x == x) // ERROR "slice can only be compared to nil|cannot compare"
74 use(f == f) // ERROR "func can only be compared to nil|cannot compare"
75 use(m == m) // ERROR "map can only be compared to nil|cannot compare"
77 // Comparison with interface that cannot return true
80 use(i == x) // ERROR "invalid operation"
81 use(x == i) // ERROR "invalid operation"
82 use(i == f) // ERROR "invalid operation"
83 use(f == i) // ERROR "invalid operation"
84 use(i == m) // ERROR "invalid operation"
85 use(m == i) // ERROR "invalid operation"