Skip to content

Commit

Permalink
buildifier: fix uninitialised check when using list unpack assignment (
Browse files Browse the repository at this point in the history
…#1202)

as the test added in this commit shows, prior to this commit, the
uninitialized check would incorrectly fail when using list unpack
assignment, if the same variable is reused later.

this modified CollectLValues, so that it supports list unpack
assignments (in addition to tuple, and normal assignments).
  • Loading branch information
Gandem authored Oct 9, 2023
1 parent 73b832e commit af7d35f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions bzlenv/bzlenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ func CollectLValues(node build.Expr) []*build.Ident {
for _, item := range node.List {
result = append(result, CollectLValues(item)...)
}
case *build.ListExpr:
for _, item := range node.List {
result = append(result, CollectLValues(item)...)
}
}
return result
}
Expand Down
9 changes: 9 additions & 0 deletions warn/warn_control_flow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1281,6 +1281,15 @@ def foo():
for x, y in z:
bar(x)
`,
[]string{},
scopeEverywhere)

checkFindings(t, "uninitialized", `
def foo():
[x, y] = [1, 2]
x = 3
print(x)
`,
[]string{},
scopeEverywhere)
Expand Down

0 comments on commit af7d35f

Please sign in to comment.