From 5b2bf39cbad10fab6148acba1b7893ae8a6d8789 Mon Sep 17 00:00:00 2001 From: Christoph Brandau Date: Wed, 13 Aug 2025 09:26:22 +0200 Subject: [PATCH] fix foreach var --- server/src/tools/checks.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/server/src/tools/checks.py b/server/src/tools/checks.py index 6971779..3b8367a 100644 --- a/server/src/tools/checks.py +++ b/server/src/tools/checks.py @@ -120,6 +120,22 @@ class UndeclaredVariableCheck(Visitor): base = text.split("(", 1)[0] # Handle array syntax if not base.startswith("::"): 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 for ch in getattr(node, "children", []): _collect(ch)