| 1 |
package pkg |
| 2 |
|
| 3 |
func fn1(x interface{}) { |
| 4 |
if x, ok := x.(int); ok { |
| 5 |
_ = x |
| 6 |
} else { |
| 7 |
_ = x //@ diag(`x refers to the result of a failed type assertion`) |
| 8 |
x = 1 |
| 9 |
// No diagnostic, x is no longer the zero value |
| 10 |
_ = x |
| 11 |
} |
| 12 |
|
| 13 |
if x, ok := x.(int); ok { |
| 14 |
} else { |
| 15 |
_ = x //@ diag(`x refers to the result of a failed type assertion`) |
| 16 |
_ = &x |
| 17 |
_ = x |
| 18 |
} |
| 19 |
|
| 20 |
if y, ok := x.(int); ok { |
| 21 |
_ = y |
| 22 |
} else { |
| 23 |
// No diagnostic because x isn't shadowed |
| 24 |
_ = x |
| 25 |
} |
| 26 |
|
| 27 |
if y, ok := x.(int); ok { |
| 28 |
_ = y |
| 29 |
} else { |
| 30 |
// No diagnostic because y isn't shadowing x |
| 31 |
_ = y |
| 32 |
} |
| 33 |
|
| 34 |
if x, ok := x.(int); ok && true { |
| 35 |
_ = x |
| 36 |
} else { |
| 37 |
// No diagnostic because the condition isn't simply 'ok' |
| 38 |
_ = x |
| 39 |
} |
| 40 |
|
| 41 |
if x, ok := x.(*int); ok { |
| 42 |
_ = x |
| 43 |
} else if x != nil { //@ diag(`x refers to`) |
| 44 |
} else if x == nil { //@ diag(`x refers to`) |
| 45 |
} |
| 46 |
} |