]> Cypherpunks.ru repositories - gostls13.git/blob - test/cmp6.go
gc: remove func, map compare
[gostls13.git] / test / cmp6.go
1 // errchk $G -e $D/$F.go
2
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.
6
7 package main
8
9 func use(bool) {}
10
11 type T1 *int
12 type T2 *int
13
14 type T3 struct{}
15
16 var t3 T3
17
18 func main() {
19         // Arguments to comparison must be
20         // assignable one to the other (or vice versa)
21         // so chan int can be compared against
22         // directional channels but channel of different
23         // direction cannot be compared against each other.
24         var c1 chan<- int
25         var c2 <-chan int
26         var c3 chan int
27
28         use(c1 == c2) // ERROR "invalid operation|incompatible"
29         use(c2 == c1) // ERROR "invalid operation|incompatible"
30         use(c1 == c3)
31         use(c2 == c2)
32         use(c3 == c1)
33         use(c3 == c2)
34
35         // Same applies to named types.
36         var p1 T1
37         var p2 T2
38         var p3 *int
39
40         use(p1 == p2) // ERROR "invalid operation|incompatible"
41         use(p2 == p1) // ERROR "invalid operation|incompatible"
42         use(p1 == p3)
43         use(p2 == p2)
44         use(p3 == p1)
45         use(p3 == p2)
46
47         // Comparison of structs should have a good message
48         use(t3 == t3) // ERROR "struct|expected"
49
50         // Slices, functions, and maps too.
51         var x []int
52         var f func()
53         var m map[int]int
54         use(x == x) // ERROR "slice can only be compared to nil"
55         use(f == f) // ERROR "func can only be compared to nil"
56         use(m == m) // ERROR "map can only be compared to nil"
57 }