From 8b859e4ed78a2f40b5d8c3af94644f8674059da8 Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Fri, 9 Feb 2024 10:07:37 -0500 Subject: [PATCH] add test for topsort analysis --- .../unit/semantics/analysis/test_for_loop.py | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/unit/semantics/analysis/test_for_loop.py b/tests/unit/semantics/analysis/test_for_loop.py index c538ce6b7d0..c755706d012 100644 --- a/tests/unit/semantics/analysis/test_for_loop.py +++ b/tests/unit/semantics/analysis/test_for_loop.py @@ -134,6 +134,31 @@ def baz(): validate_semantics(vyper_module, dummy_input_bundle) +def test_modify_iterator_recursive_function_call_topsort(dummy_input_bundle): + # test the analysis works no matter the order of functions + code = """ +a: uint256[3] + +@internal +def baz(): + for i: uint256 in self.a: + self.bar() + +@internal +def bar(): + self.foo() + +@internal +def foo(): + self.a[0] = 1 + """ + vyper_module = parse_to_ast(code) + with pytest.raises(ImmutableViolation) as e: + validate_semantics(vyper_module, dummy_input_bundle) + + assert e.value._message == "Cannot modify loop variable `a`" + + def test_modify_iterator_through_struct(dummy_input_bundle): # GH issue 3429 code = """