Josh Bleecher Snyder | 77a2113 | 2014-12-23 18:28:02 -0800 | [diff] [blame] | 1 | // errorcheck |
| 2 | |
| 3 | // Copyright 2014 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 | // Verify that concrete/interface comparisons are |
| 8 | // typechecked correctly by the compiler. |
| 9 | |
| 10 | package main |
| 11 | |
| 12 | type I interface { |
| 13 | Method() |
| 14 | } |
| 15 | |
| 16 | type C int |
| 17 | |
| 18 | func (C) Method() {} |
| 19 | |
| 20 | type G func() |
| 21 | |
| 22 | func (G) Method() {} |
| 23 | |
| 24 | var ( |
| 25 | e interface{} |
| 26 | i I |
| 27 | c C |
| 28 | n int |
| 29 | f func() |
| 30 | g G |
| 31 | ) |
| 32 | |
| 33 | var ( |
| 34 | _ = e == c |
| 35 | _ = e != c |
| 36 | _ = e >= c // ERROR "invalid operation.*not defined" |
| 37 | _ = c == e |
| 38 | _ = c != e |
| 39 | _ = c >= e // ERROR "invalid operation.*not defined" |
| 40 | |
| 41 | _ = i == c |
| 42 | _ = i != c |
| 43 | _ = i >= c // ERROR "invalid operation.*not defined" |
| 44 | _ = c == i |
| 45 | _ = c != i |
| 46 | _ = c >= i // ERROR "invalid operation.*not defined" |
| 47 | |
| 48 | _ = e == n |
| 49 | _ = e != n |
| 50 | _ = e >= n // ERROR "invalid operation.*not defined" |
| 51 | _ = n == e |
| 52 | _ = n != e |
| 53 | _ = n >= e // ERROR "invalid operation.*not defined" |
| 54 | |
| 55 | // i and n are not assignable to each other |
| 56 | _ = i == n // ERROR "invalid operation.*mismatched types" |
| 57 | _ = i != n // ERROR "invalid operation.*mismatched types" |
| 58 | _ = i >= n // ERROR "invalid operation.*mismatched types" |
| 59 | _ = n == i // ERROR "invalid operation.*mismatched types" |
| 60 | _ = n != i // ERROR "invalid operation.*mismatched types" |
| 61 | _ = n >= i // ERROR "invalid operation.*mismatched types" |
| 62 | |
| 63 | _ = e == 1 |
| 64 | _ = e != 1 |
| 65 | _ = e >= 1 // ERROR "invalid operation.*not defined" |
| 66 | _ = 1 == e |
| 67 | _ = 1 != e |
| 68 | _ = 1 >= e // ERROR "invalid operation.*not defined" |
| 69 | |
| 70 | _ = i == 1 // ERROR "invalid operation.*mismatched types" |
| 71 | _ = i != 1 // ERROR "invalid operation.*mismatched types" |
| 72 | _ = i >= 1 // ERROR "invalid operation.*mismatched types" |
| 73 | _ = 1 == i // ERROR "invalid operation.*mismatched types" |
| 74 | _ = 1 != i // ERROR "invalid operation.*mismatched types" |
| 75 | _ = 1 >= i // ERROR "invalid operation.*mismatched types" |
| 76 | |
| 77 | _ = e == f // ERROR "invalid operation.*not defined" |
| 78 | _ = e != f // ERROR "invalid operation.*not defined" |
| 79 | _ = e >= f // ERROR "invalid operation.*not defined" |
| 80 | _ = f == e // ERROR "invalid operation.*not defined" |
| 81 | _ = f != e // ERROR "invalid operation.*not defined" |
| 82 | _ = f >= e // ERROR "invalid operation.*not defined" |
| 83 | |
| 84 | _ = i == f // ERROR "invalid operation.*mismatched types" |
| 85 | _ = i != f // ERROR "invalid operation.*mismatched types" |
| 86 | _ = i >= f // ERROR "invalid operation.*mismatched types" |
| 87 | _ = f == i // ERROR "invalid operation.*mismatched types" |
| 88 | _ = f != i // ERROR "invalid operation.*mismatched types" |
| 89 | _ = f >= i // ERROR "invalid operation.*mismatched types" |
| 90 | |
| 91 | _ = e == g // ERROR "invalid operation.*not defined" |
| 92 | _ = e != g // ERROR "invalid operation.*not defined" |
| 93 | _ = e >= g // ERROR "invalid operation.*not defined" |
| 94 | _ = g == e // ERROR "invalid operation.*not defined" |
| 95 | _ = g != e // ERROR "invalid operation.*not defined" |
| 96 | _ = g >= e // ERROR "invalid operation.*not defined" |
| 97 | |
| 98 | _ = i == g // ERROR "invalid operation.*not defined" |
| 99 | _ = i != g // ERROR "invalid operation.*not defined" |
| 100 | _ = i >= g // ERROR "invalid operation.*not defined" |
| 101 | _ = g == i // ERROR "invalid operation.*not defined" |
| 102 | _ = g != i // ERROR "invalid operation.*not defined" |
| 103 | _ = g >= i // ERROR "invalid operation.*not defined" |
| 104 | |
| 105 | _ = _ == e // ERROR "cannot use _ as value" |
| 106 | _ = _ == i // ERROR "cannot use _ as value" |
| 107 | _ = _ == c // ERROR "cannot use _ as value" |
| 108 | _ = _ == n // ERROR "cannot use _ as value" |
| 109 | _ = _ == f // ERROR "cannot use _ as value" |
| 110 | _ = _ == g // ERROR "cannot use _ as value" |
| 111 | |
| 112 | _ = e == _ // ERROR "cannot use _ as value" |
| 113 | _ = i == _ // ERROR "cannot use _ as value" |
| 114 | _ = c == _ // ERROR "cannot use _ as value" |
| 115 | _ = n == _ // ERROR "cannot use _ as value" |
| 116 | _ = f == _ // ERROR "cannot use _ as value" |
| 117 | _ = g == _ // ERROR "cannot use _ as value" |
| 118 | |
| 119 | _ = _ == _ // ERROR "cannot use _ as value" |
| 120 | |
| 121 | _ = e ^ c // ERROR "invalid operation.*mismatched types" |
| 122 | _ = c ^ e // ERROR "invalid operation.*mismatched types" |
| 123 | _ = 1 ^ e // ERROR "invalid operation.*mismatched types" |
| 124 | _ = e ^ 1 // ERROR "invalid operation.*mismatched types" |
| 125 | _ = 1 ^ c |
| 126 | _ = c ^ 1 |
| 127 | ) |