Skip to content

Commit af7d35f

Browse files
authored
buildifier: fix uninitialised check when using list unpack assignment (#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).
1 parent 73b832e commit af7d35f

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

bzlenv/bzlenv.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ func CollectLValues(node build.Expr) []*build.Ident {
148148
for _, item := range node.List {
149149
result = append(result, CollectLValues(item)...)
150150
}
151+
case *build.ListExpr:
152+
for _, item := range node.List {
153+
result = append(result, CollectLValues(item)...)
154+
}
151155
}
152156
return result
153157
}

warn/warn_control_flow_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,6 +1281,15 @@ def foo():
12811281
12821282
for x, y in z:
12831283
bar(x)
1284+
`,
1285+
[]string{},
1286+
scopeEverywhere)
1287+
1288+
checkFindings(t, "uninitialized", `
1289+
def foo():
1290+
[x, y] = [1, 2]
1291+
x = 3
1292+
print(x)
12841293
`,
12851294
[]string{},
12861295
scopeEverywhere)

0 commit comments

Comments
 (0)