Skip to content

Commit

Permalink
S1009: handle shadowed len
Browse files Browse the repository at this point in the history
Closes gh-1181

(cherry picked from commit e3efe9b)
  • Loading branch information
dominikh committed May 16, 2022
1 parent b6a3bc8 commit ce49d7b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
3 changes: 1 addition & 2 deletions simple/lint.go
Expand Up @@ -659,8 +659,7 @@ func CheckRedundantNilCheckWithLen(pass *analysis.Pass) (interface{}, error) {
if !ok {
return
}
yxFun, ok := yx.Fun.(*ast.Ident)
if !ok || yxFun.Name != "len" || len(yx.Args) != 1 {
if !code.IsCallTo(pass, yx, "len") {
return
}
yxArg, ok := yx.Args[knowledge.Arg("len.v")].(*ast.Ident)
Expand Down
11 changes: 11 additions & 0 deletions simple/testdata/src/CheckRedundantNilCheckWithLen/nil-len.go
Expand Up @@ -62,3 +62,14 @@ func fn() {
if s != nil && len(s) != len(ch) { // nil check is not redundant here
}
}

func fn3() {
var x []int

if x == nil || len(x) == 0 { //@ diag(`should omit nil check`)
}

len := func([]int) int { return 10 }
if x == nil || len(x) == 0 {
}
}

0 comments on commit ce49d7b

Please sign in to comment.