Source file test/fixedbugs/issue9370.go
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|invalid comparison|cannot compare" 37 _ = c == e 38 _ = c != e 39 _ = c >= e // ERROR "invalid operation.*not defined|invalid comparison|cannot compare" 40 41 _ = i == c 42 _ = i != c 43 _ = i >= c // ERROR "invalid operation.*not defined|invalid comparison|cannot compare" 44 _ = c == i 45 _ = c != i 46 _ = c >= i // ERROR "invalid operation.*not defined|invalid comparison|cannot compare" 47 48 _ = e == n 49 _ = e != n 50 _ = e >= n // ERROR "invalid operation.*not defined|invalid comparison|cannot compare" 51 _ = n == e 52 _ = n != e 53 _ = n >= e // ERROR "invalid operation.*not defined|invalid comparison|cannot compare" 54 55 // i and n are not assignable to each other 56 _ = i == n // ERROR "invalid operation.*mismatched types|incompatible types" 57 _ = i != n // ERROR "invalid operation.*mismatched types|incompatible types" 58 _ = i >= n // ERROR "invalid operation.*mismatched types|incompatible types" 59 _ = n == i // ERROR "invalid operation.*mismatched types|incompatible types" 60 _ = n != i // ERROR "invalid operation.*mismatched types|incompatible types" 61 _ = n >= i // ERROR "invalid operation.*mismatched types|incompatible types" 62 63 _ = e == 1 64 _ = e != 1 65 _ = e >= 1 // ERROR "invalid operation.*not defined|invalid comparison" 66 _ = 1 == e 67 _ = 1 != e 68 _ = 1 >= e // ERROR "invalid operation.*not defined|invalid comparison" 69 70 _ = i == 1 // ERROR "invalid operation.*mismatched types|incompatible types|cannot convert" 71 _ = i != 1 // ERROR "invalid operation.*mismatched types|incompatible types|cannot convert" 72 _ = i >= 1 // ERROR "invalid operation.*mismatched types|incompatible types|cannot convert" 73 _ = 1 == i // ERROR "invalid operation.*mismatched types|incompatible types|cannot convert" 74 _ = 1 != i // ERROR "invalid operation.*mismatched types|incompatible types|cannot convert" 75 _ = 1 >= i // ERROR "invalid operation.*mismatched types|incompatible types|cannot convert" 76 77 _ = e == f // ERROR "invalid operation.*not defined|invalid operation" 78 _ = e != f // ERROR "invalid operation.*not defined|invalid operation" 79 _ = e >= f // ERROR "invalid operation.*not defined|invalid comparison" 80 _ = f == e // ERROR "invalid operation.*not defined|invalid operation" 81 _ = f != e // ERROR "invalid operation.*not defined|invalid operation" 82 _ = f >= e // ERROR "invalid operation.*not defined|invalid comparison" 83 84 _ = i == f // ERROR "invalid operation.*mismatched types|incompatible types" 85 _ = i != f // ERROR "invalid operation.*mismatched types|incompatible types" 86 _ = i >= f // ERROR "invalid operation.*mismatched types|incompatible types" 87 _ = f == i // ERROR "invalid operation.*mismatched types|incompatible types" 88 _ = f != i // ERROR "invalid operation.*mismatched types|incompatible types" 89 _ = f >= i // ERROR "invalid operation.*mismatched types|incompatible types" 90 91 _ = e == g // ERROR "invalid operation.*not defined|invalid operation" 92 _ = e != g // ERROR "invalid operation.*not defined|invalid operation" 93 _ = e >= g // ERROR "invalid operation.*not defined|invalid comparison" 94 _ = g == e // ERROR "invalid operation.*not defined|invalid operation" 95 _ = g != e // ERROR "invalid operation.*not defined|invalid operation" 96 _ = g >= e // ERROR "invalid operation.*not defined|invalid comparison" 97 98 _ = i == g // ERROR "invalid operation.*not defined|invalid operation" 99 _ = i != g // ERROR "invalid operation.*not defined|invalid operation" 100 _ = i >= g // ERROR "invalid operation.*not defined|invalid comparison" 101 _ = g == i // ERROR "invalid operation.*not defined|invalid operation" 102 _ = g != i // ERROR "invalid operation.*not defined|invalid operation" 103 _ = g >= i // ERROR "invalid operation.*not defined|invalid comparison" 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|incompatible types" 122 _ = c ^ e // ERROR "invalid operation.*mismatched types|incompatible types" 123 _ = 1 ^ e // ERROR "invalid operation.*mismatched types|incompatible types" 124 _ = e ^ 1 // ERROR "invalid operation.*mismatched types|incompatible types" 125 _ = 1 ^ c 126 _ = c ^ 1 127 ) 128