| 1 |
package pkg |
| 2 |
|
| 3 |
import "io" |
| 4 |
|
| 5 |
type T struct{} |
| 6 |
|
| 7 |
func (T) Read(b []byte) (int, error) { return 0, nil } |
| 8 |
func (T) something() string { return "non-exported method" } |
| 9 |
|
| 10 |
type V error |
| 11 |
type U error |
| 12 |
|
| 13 |
func fn1() { |
| 14 |
var ( |
| 15 |
v interface{} |
| 16 |
err error |
| 17 |
) |
| 18 |
|
| 19 |
switch v.(type) { |
| 20 |
case io.Reader: |
| 21 |
println("io.Reader") |
| 22 |
case io.ReadCloser: //@ diag(`unreachable case clause: io.Reader will always match before io.ReadCloser`) |
| 23 |
println("io.ReadCloser") |
| 24 |
} |
| 25 |
|
| 26 |
switch v.(type) { |
| 27 |
case io.Reader: |
| 28 |
println("io.Reader") |
| 29 |
case T: //@ diag(`unreachable case clause: io.Reader will always match before example.com/CheckUnreachableTypeCases.T`) |
| 30 |
println("T") |
| 31 |
} |
| 32 |
|
| 33 |
switch v.(type) { |
| 34 |
case io.Reader: |
| 35 |
println("io.Reader") |
| 36 |
case io.ReadCloser: //@ diag(`unreachable case clause: io.Reader will always match before io.ReadCloser`) |
| 37 |
println("io.ReadCloser") |
| 38 |
case T: //@ diag(`unreachable case clause: io.Reader will always match before example.com/CheckUnreachableTypeCases.T`) |
| 39 |
println("T") |
| 40 |
} |
| 41 |
|
| 42 |
switch v.(type) { |
| 43 |
case io.Reader: |
| 44 |
println("io.Reader") |
| 45 |
case io.ReadCloser, T: //@ diag(`unreachable case clause: io.Reader will always match before io.ReadCloser`) |
| 46 |
println("io.ReadCloser or T") |
| 47 |
} |
| 48 |
|
| 49 |
switch v.(type) { |
| 50 |
case io.ReadCloser, io.Reader: |
| 51 |
println("io.ReadCloser or io.Reader") |
| 52 |
case T: //@ diag(`unreachable case clause: io.Reader will always match before example.com/CheckUnreachableTypeCases.T`) |
| 53 |
println("T") |
| 54 |
} |
| 55 |
|
| 56 |
switch v.(type) { |
| 57 |
default: |
| 58 |
println("something else") |
| 59 |
case io.Reader: |
| 60 |
println("io.Reader") |
| 61 |
case T: //@ diag(`unreachable case clause: io.Reader will always match before example.com/CheckUnreachableTypeCases.T`) |
| 62 |
println("T") |
| 63 |
} |
| 64 |
|
| 65 |
switch v.(type) { |
| 66 |
case interface{}: |
| 67 |
println("interface{}") |
| 68 |
case nil, T: //@ diag(`unreachable case clause: interface{} will always match before example.com/CheckUnreachableTypeCases.T`) |
| 69 |
println("nil or T") |
| 70 |
} |
| 71 |
|
| 72 |
switch err.(type) { |
| 73 |
case V: |
| 74 |
println("V") |
| 75 |
case U: //@ diag(`unreachable case clause: example.com/CheckUnreachableTypeCases.V will always match before example.com/CheckUnreachableTypeCases.U`) |
| 76 |
println("U") |
| 77 |
} |
| 78 |
|
| 79 |
switch err.(type) { |
| 80 |
case U: |
| 81 |
println("U") |
| 82 |
case V: //@ diag(`unreachable case clause: example.com/CheckUnreachableTypeCases.U will always match before example.com/CheckUnreachableTypeCases.V`) |
| 83 |
println("V") |
| 84 |
} |
| 85 |
} |
| 86 |
|
| 87 |
func fn3() { |
| 88 |
var ( |
| 89 |
v interface{} |
| 90 |
err error |
| 91 |
) |
| 92 |
|
| 93 |
switch v.(type) { |
| 94 |
case T: |
| 95 |
println("T") |
| 96 |
case io.Reader: |
| 97 |
println("io.Reader") |
| 98 |
} |
| 99 |
|
| 100 |
switch v.(type) { |
| 101 |
case io.ReadCloser: |
| 102 |
println("io.ReadCloser") |
| 103 |
case T: |
| 104 |
println("T") |
| 105 |
} |
| 106 |
|
| 107 |
switch v.(type) { |
| 108 |
case io.ReadCloser: |
| 109 |
println("io.ReadCloser") |
| 110 |
case io.Reader: |
| 111 |
println("io.Reader") |
| 112 |
} |
| 113 |
|
| 114 |
switch v.(type) { |
| 115 |
case T: |
| 116 |
println("T") |
| 117 |
} |
| 118 |
|
| 119 |
switch err.(type) { |
| 120 |
case V, U: |
| 121 |
println("V or U") |
| 122 |
case io.Reader: |
| 123 |
println("io.Reader") |
| 124 |
} |
| 125 |
|
| 126 |
switch v.(type) { |
| 127 |
default: |
| 128 |
println("something") |
| 129 |
} |
| 130 |
|
| 131 |
switch v.(type) { |
| 132 |
case interface{}: |
| 133 |
println("interface{}") |
| 134 |
case nil: |
| 135 |
println("nil") |
| 136 |
} |
| 137 |
} |