| 1 |
package pkg |
| 2 |
|
| 3 |
func gen() []int { return make([]int, 1) } |
| 4 |
|
| 5 |
func fn() { |
| 6 |
var pa *[5]int |
| 7 |
var s []int |
| 8 |
var m map[int]int |
| 9 |
var ch chan int |
| 10 |
|
| 11 |
if s == nil || len(s) == 0 { //@ diag(re`should omit nil check.+for nil slices`) |
| 12 |
} |
| 13 |
if m == nil || len(m) == 0 { //@ diag(re`should omit nil check.+for nil maps`) |
| 14 |
} |
| 15 |
if ch == nil || len(ch) == 0 { //@ diag(re`should omit nil check.+for nil channels`) |
| 16 |
} |
| 17 |
|
| 18 |
if s != nil && len(s) != 0 { //@ diag(`should omit nil check`) |
| 19 |
} |
| 20 |
if m != nil && len(m) > 0 { //@ diag(`should omit nil check`) |
| 21 |
} |
| 22 |
if s != nil && len(s) > 5 { //@ diag(`should omit nil check`) |
| 23 |
} |
| 24 |
if s != nil && len(s) >= 5 { //@ diag(`should omit nil check`) |
| 25 |
} |
| 26 |
const five = 5 |
| 27 |
if s != nil && len(s) == five { //@ diag(`should omit nil check`) |
| 28 |
} |
| 29 |
|
| 30 |
if ch != nil && len(ch) == 5 { //@ diag(`should omit nil check`) |
| 31 |
} |
| 32 |
|
| 33 |
if pa == nil || len(pa) == 0 { // nil check cannot be removed with pointer to an array |
| 34 |
} |
| 35 |
if s == nil || len(m) == 0 { // different variables |
| 36 |
} |
| 37 |
if s != nil && len(m) == 1 { // different variables |
| 38 |
} |
| 39 |
|
| 40 |
var ch2 chan int |
| 41 |
if ch == ch2 || len(ch) == 0 { // not comparing with nil |
| 42 |
} |
| 43 |
if ch != ch2 && len(ch) != 0 { // not comparing with nil |
| 44 |
} |
| 45 |
|
| 46 |
const zero = 0 |
| 47 |
if s != nil && len(s) == zero { // nil check is not redundant here |
| 48 |
} |
| 49 |
if s != nil && len(s) == 0 { // nil check is not redundant here |
| 50 |
} |
| 51 |
if s != nil && len(s) >= 0 { // nil check is not redundant here (though len(s) >= 0 is) |
| 52 |
} |
| 53 |
one := 1 |
| 54 |
if s != nil && len(s) == one { // nil check is not redundant here |
| 55 |
} |
| 56 |
if s != nil && len(s) == len(m) { // nil check is not redundant here |
| 57 |
} |
| 58 |
if s != nil && len(s) != 1 { // nil check is not redundant here |
| 59 |
} |
| 60 |
if s != nil && len(s) < 5 { // nil check is not redundant here |
| 61 |
} |
| 62 |
if s != nil && len(s) <= 5 { // nil check is not redundant here |
| 63 |
} |
| 64 |
if s != nil && len(s) != len(ch) { // nil check is not redundant here |
| 65 |
} |
| 66 |
|
| 67 |
if gen() != nil && len(gen()) != 0 { // nil check is not redundant, gen() isn't pure |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
func fn3() { |
| 72 |
var x []int |
| 73 |
|
| 74 |
if x == nil || len(x) == 0 { //@ diag(`should omit nil check`) |
| 75 |
} |
| 76 |
|
| 77 |
len := func([]int) int { return 10 } |
| 78 |
if x == nil || len(x) == 0 { |
| 79 |
} |
| 80 |
} |
| 81 |
|
| 82 |
func issue1527() { |
| 83 |
var t struct { |
| 84 |
pa *[5]int |
| 85 |
s []int |
| 86 |
m map[uint64]bool |
| 87 |
ch chan int |
| 88 |
} |
| 89 |
|
| 90 |
if t.s == nil || len(t.s) == 0 { //@ diag(`should omit nil check`) |
| 91 |
} |
| 92 |
if t.m == nil || len(t.m) == 0 { //@ diag(`should omit nil check`) |
| 93 |
} |
| 94 |
if t.ch == nil || len(t.ch) == 0 { //@ diag(`should omit nil check`) |
| 95 |
} |
| 96 |
if t.pa == nil || len(t.pa) == 0 { // nil check cannot be removed with pointer to an array |
| 97 |
} |
| 98 |
} |
| 99 |
|
| 100 |
func issue1605() { |
| 101 |
var s []int |
| 102 |
var m map[int]int |
| 103 |
var ch chan int |
| 104 |
|
| 105 |
if s == nil || len(s) <= 0 { //@ diag(`should omit nil check`) |
| 106 |
} |
| 107 |
if m == nil || len(m) <= 0 { //@ diag(`should omit nil check`) |
| 108 |
} |
| 109 |
if ch == nil || len(ch) <= 0 { //@ diag(`should omit nil check`) |
| 110 |
} |
| 111 |
|
| 112 |
if s == nil || len(s) < 2 { //@ diag(`should omit nil check`) |
| 113 |
} |
| 114 |
if m == nil || len(m) < 2 { //@ diag(`should omit nil check`) |
| 115 |
} |
| 116 |
if ch == nil || len(ch) < 2 { //@ diag(`should omit nil check`) |
| 117 |
} |
| 118 |
|
| 119 |
if s == nil || len(s) <= 2 { //@ diag(`should omit nil check`) |
| 120 |
} |
| 121 |
if m == nil || len(m) <= 2 { //@ diag(`should omit nil check`) |
| 122 |
} |
| 123 |
if ch == nil || len(ch) <= 2 { //@ diag(`should omit nil check`) |
| 124 |
} |
| 125 |
|
| 126 |
if s == nil || len(s) < 0 { // nil check is not redundant here (len(s) < 0 is impossible) |
| 127 |
} |
| 128 |
if m == nil || len(m) < 0 { // nil check is not redundant here (len(m) < 0 is impossible) |
| 129 |
} |
| 130 |
if ch == nil || len(ch) < 0 { // nil check is not redundant here (len(ch) < 0 is impossible) |
| 131 |
} |
| 132 |
|
| 133 |
if s == nil || len(s) > 2 { // nil check is not redundant here |
| 134 |
} |
| 135 |
if m == nil || len(m) > 2 { // nil check is not redundant here |
| 136 |
} |
| 137 |
if ch == nil || len(ch) > 2 { // nil check is not redundant here |
| 138 |
} |
| 139 |
} |