feat: regsub variable declaration check

This commit is contained in:
Christoph Brandau
2025-08-19 13:13:17 +02:00
parent 54a2e5892b
commit bf0f36dc99
+9
View File
@@ -120,6 +120,15 @@ 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 == "regsub" and node.args:
# regsub ?switches? exp string subSpec ?varName?
# If a varName is provided as the last arg, treat it as a local
last_arg = node.args[-1]
text = _word_text(last_arg)
if text:
base = text.split("(", 1)[0]
if base and not base.startswith("::"):
locals_set.add(base)
elif name == "foreach" and len(node.args) >= 3: elif name == "foreach" and len(node.args) >= 3:
# foreach varlist1 list1 ?varlist2 list2 ...? body # foreach varlist1 list1 ?varlist2 list2 ...? body
# Treat loop variables as locals within the proc # Treat loop variables as locals within the proc