blob: 4c06011873154640517caf52ed81cec8801b6179 [file] [log] [blame]
Russ Cox23bd2142010-09-13 15:42:47 -04001// 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
7package main
8
9func use(bool) {}
10
11type T1 *int
12type T2 *int
13
Russ Cox7e846662011-01-21 18:15:59 -050014type T3 struct {}
15
16var t3 T3
17
Russ Cox23bd2142010-09-13 15:42:47 -040018func 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"
29 use(c2 == c1) // ERROR "invalid operation"
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"
41 use(p2 == p1) // ERROR "invalid operation"
42 use(p1 == p3)
43 use(p2 == p2)
44 use(p3 == p1)
45 use(p3 == p2)
Russ Cox7e846662011-01-21 18:15:59 -050046
47 // Comparison of structs should have a good message
48 use(t3 == t3) // ERROR "struct"
Russ Cox23bd2142010-09-13 15:42:47 -040049}