Russ Cox | 23bd214 | 2010-09-13 15:42:47 -0400 | [diff] [blame] | 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 | |
Russ Cox | 7e84666 | 2011-01-21 18:15:59 -0500 | [diff] [blame] | 14 | type T3 struct {} |
| 15 | |
| 16 | var t3 T3 |
| 17 | |
Russ Cox | 23bd214 | 2010-09-13 15:42:47 -0400 | [diff] [blame] | 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" |
| 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 Cox | 7e84666 | 2011-01-21 18:15:59 -0500 | [diff] [blame] | 46 | |
| 47 | // Comparison of structs should have a good message |
| 48 | use(t3 == t3) // ERROR "struct" |
Russ Cox | 23bd214 | 2010-09-13 15:42:47 -0400 | [diff] [blame] | 49 | } |