Skip to content

Commit

Permalink
fix handling of vy_ast.arg nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
charles-cooper committed Jun 22, 2024
1 parent 7779b6a commit 09dd1a3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
16 changes: 16 additions & 0 deletions tests/functional/codegen/features/iteration/test_for_in_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -914,3 +914,19 @@ def foo() -> DynArray[uint256, 10]:
"""
c = get_contract(code)
assert c.foo() == [1, 2, 3, 4]


def test_iterator_modification_func_arg(get_contract):
code = """
@internal
def boo(a: DynArray[uint256, 12] = [], b: DynArray[uint256, 12] = []) -> DynArray[uint256, 12]:
for i: uint256 in a:
b.append(i)
return b
@external
def foo() -> DynArray[uint256, 12]:
return self.boo([1, 2, 3])
"""
c = get_contract(code)
assert c.foo() == [1, 2, 3]
5 changes: 4 additions & 1 deletion vyper/semantics/analysis/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,10 @@ def to_dict(self):
# map SUBSCRIPT_ACCESS to `"$subscript_access"` (which is an identifier
# which can't be constructed by the user)
path = ["$subscript_access" if s is self.SUBSCRIPT_ACCESS else s for s in self.path]
varname = var.decl_node.target.id
if isinstance(var.decl_node, vy_ast.arg):
varname = var.decl_node.arg
else:
varname = var.decl_node.target.id

decl_node = var.decl_node.get_id_dict()
ret = {"name": varname, "decl_node": decl_node, "access_path": path}
Expand Down
2 changes: 1 addition & 1 deletion vyper/semantics/analysis/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ def analyze(self):

for arg in self.func.arguments:
self.namespace[arg.name] = VarInfo(
arg.typ, location=location, modifiability=modifiability, decl_node=arg
arg.typ, location=location, modifiability=modifiability, decl_node=arg.ast_source
)

for node in self.fn_node.body:
Expand Down

0 comments on commit 09dd1a3

Please sign in to comment.