diff --git a/mesonbuild/ast/printer.py b/mesonbuild/ast/printer.py index 020299d6b..410aabd46 100644 --- a/mesonbuild/ast/printer.py +++ b/mesonbuild/ast/printer.py @@ -185,7 +185,7 @@ class AstPrinter(AstVisitor): def visit_ForeachClauseNode(self, node: mparser.ForeachClauseNode) -> None: node.lineno = self.curr_line or node.lineno self.append_padded('foreach', node) - self.append_padded(', '.join(node.varnames), node) + self.append_padded(', '.join(varname.value for varname in node.varnames), node) self.append_padded(':', node) node.items.accept(self) self.newline() @@ -373,7 +373,7 @@ class AstJSONPrinter(AstVisitor): def visit_ForeachClauseNode(self, node: mparser.ForeachClauseNode) -> None: self._accept('items', node.items) self._accept('block', node.block) - self.current['varnames'] = node.varnames + self.current['varnames'] = [varname.value for varname in node.varnames] self.setbase(node) def visit_IfClauseNode(self, node: mparser.IfClauseNode) -> None: diff --git a/mesonbuild/ast/visitor.py b/mesonbuild/ast/visitor.py index 6e40ea0b4..5b1fb6a09 100644 --- a/mesonbuild/ast/visitor.py +++ b/mesonbuild/ast/visitor.py @@ -123,6 +123,8 @@ class AstVisitor: def visit_ForeachClauseNode(self, node: mparser.ForeachClauseNode) -> None: self.visit_default_func(node) + for varname in node.varnames: + varname.accept(self) node.items.accept(self) node.block.accept(self) diff --git a/mesonbuild/interpreterbase/interpreterbase.py b/mesonbuild/interpreterbase/interpreterbase.py index 1c0912835..7e3f8da5a 100644 --- a/mesonbuild/interpreterbase/interpreterbase.py +++ b/mesonbuild/interpreterbase/interpreterbase.py @@ -459,14 +459,14 @@ class InterpreterBase: if tsize is None: if isinstance(i, tuple): raise mesonlib.MesonBugException(f'Iteration of {items} returned a tuple even though iter_tuple_size() is None') - self.set_variable(node.varnames[0], self._holderify(i)) + self.set_variable(node.varnames[0].value, self._holderify(i)) else: if not isinstance(i, tuple): raise mesonlib.MesonBugException(f'Iteration of {items} did not return a tuple even though iter_tuple_size() is {tsize}') if len(i) != tsize: raise mesonlib.MesonBugException(f'Iteration of {items} did not return a tuple even though iter_tuple_size() is {tsize}') for j in range(tsize): - self.set_variable(node.varnames[j], self._holderify(i[j])) + self.set_variable(node.varnames[j].value, self._holderify(i[j])) try: self.evaluate_codeblock(node.block) except ContinueRequest: diff --git a/mesonbuild/mparser.py b/mesonbuild/mparser.py index ceddf0a52..2d7f11505 100644 --- a/mesonbuild/mparser.py +++ b/mesonbuild/mparser.py @@ -518,11 +518,11 @@ class PlusAssignmentNode(BaseNode): @dataclass(unsafe_hash=True) class ForeachClauseNode(BaseNode): - varnames: T.List[str] = field(hash=False) + varnames: T.List[IdNode] = field(hash=False) items: BaseNode block: CodeBlockNode - def __init__(self, token: Token, varnames: T.List[str], items: BaseNode, block: CodeBlockNode): + def __init__(self, token: Token, varnames: T.List[IdNode], items: BaseNode, block: CodeBlockNode): super().__init__(token.lineno, token.colno, token.filename) self.varnames = varnames self.items = items @@ -898,13 +898,13 @@ class Parser: self.expect('id') assert isinstance(t.value, str) varname = t - varnames = [t.value] + varnames = [IdNode(t)] if self.accept('comma'): t = self.current self.expect('id') assert isinstance(t.value, str) - varnames.append(t.value) + varnames.append(IdNode(t)) self.expect('colon') items = self.statement()