Skip to content

Commit

Permalink
allow iterating over subscript
Browse files Browse the repository at this point in the history
  • Loading branch information
charles-cooper committed Jan 7, 2024
1 parent 0d759c7 commit 9dcac6c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
19 changes: 12 additions & 7 deletions tests/functional/codegen/features/iteration/test_for_in_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,18 @@ def a() -> int128:
return x""",
-14,
),
(
"""
@external
def a() -> uint256:
a: DynArray[DynArray[uint256, 2], 3] = [[0, 1], [2, 3], [4, 5]]
x: uint256 = 0
for i: uint256 in a[2]:
x += i
return x
""",
9,
),
]


Expand Down Expand Up @@ -791,13 +803,6 @@ def test_for() -> int128:
""",
TypeMismatch,
),
"""
@external
def foo():
a: DynArray[DynArray[uint256, 2], 3] = [[0, 1], [2, 3], [4, 5]]
for i: uint256 in a[2]:
pass
""",
]

BAD_CODE = [code if isinstance(code, tuple) else (code, StructureException) for code in BAD_CODE]
Expand Down
3 changes: 0 additions & 3 deletions vyper/semantics/analysis/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,9 +344,6 @@ def visit_Expr(self, node):
self.expr_visitor.visit(node.value, fn_type)

def visit_For(self, node):
if isinstance(node.iter, vy_ast.Subscript):
raise StructureException("Cannot iterate over a nested list", node.iter)

if not isinstance(node.target.target, vy_ast.Name):
raise StructureException("Invalid syntax for loop iterator", node.target.target)

Expand Down

0 comments on commit 9dcac6c

Please sign in to comment.