fix foreach var
This commit is contained in:
@@ -120,6 +120,22 @@ class UndeclaredVariableCheck(Visitor):
|
|||||||
base = text.split("(", 1)[0] # Handle array syntax
|
base = text.split("(", 1)[0] # Handle array syntax
|
||||||
if not base.startswith("::"):
|
if not base.startswith("::"):
|
||||||
locals_set.add(base)
|
locals_set.add(base)
|
||||||
|
elif name == "foreach" and len(node.args) >= 3:
|
||||||
|
# foreach varlist1 list1 ?varlist2 list2 ...? body
|
||||||
|
# Treat loop variables as locals within the proc
|
||||||
|
# Iterate pairs (varlist, list) over all but the last arg (body)
|
||||||
|
pair_args = node.args[:-1]
|
||||||
|
i = 0
|
||||||
|
while i + 1 < len(pair_args):
|
||||||
|
varnode = pair_args[i]
|
||||||
|
text = _word_text(varnode) or ""
|
||||||
|
# Split var list by whitespace if braced list, else single name
|
||||||
|
names = text.split()
|
||||||
|
for nm in names:
|
||||||
|
base = nm.split("(", 1)[0]
|
||||||
|
if base and not base.startswith("::"):
|
||||||
|
locals_set.add(base)
|
||||||
|
i += 2
|
||||||
# Recurse
|
# Recurse
|
||||||
for ch in getattr(node, "children", []):
|
for ch in getattr(node, "children", []):
|
||||||
_collect(ch)
|
_collect(ch)
|
||||||
|
|||||||
Reference in New Issue
Block a user