Skip to content

Commit

Permalink
fix-vyperlang#2183: Incorrect output while passing multi-dimensional …
Browse files Browse the repository at this point in the history
…array as argument.
  • Loading branch information
saikat041 committed Oct 8, 2020
1 parent 5115867 commit 9d79b10
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
31 changes: 31 additions & 0 deletions tests/parser/types/test_lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,3 +256,34 @@ def parse_list_fail():
pass
"""
assert_compile_failed(lambda: get_contract_with_gas_estimation(code), TypeMismatch)


def test_2d_array_input_1(get_contract):
code = """
@internal
def test_input(arr: int128[2][1], i: int128) -> (int128[2][1], int128):
return arr, i
@external
def test_values(arr: int128[2][1], i: int128) -> (int128[2][1], int128):
return self.test_input(arr, i)
"""

c = get_contract(code)
assert c.test_values([[1, 2]], 3) == [[[1, 2]], 3]


def test_2d_array_input_1(get_contract):
code = """
@internal
def test_input(arr: int128[2][3], s: String[10]) -> (int128[2][3], String[10]):
return arr, s
@external
def test_values(arr: int128[2][3], s: String[10]) -> (int128[2][3], String[10]):
return self.test_input(arr, s)
"""

c = get_contract(code)
assert c.test_values([[1, 2], [3, 4], [5, 6]], "abcdef") == [[[1, 2], [3, 4], [5, 6]], "abcdef"]

6 changes: 1 addition & 5 deletions vyper/parser/parser_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,11 +498,7 @@ def pack_arguments(signature, args, context, stmt_expr, is_external_call):
[placeholder + staticarray_offset + i * 32], typ=typ, location="memory",
)
setters.append(make_setter(target, arg, "memory", pos=pos))
if isinstance(typ, ListType):
count = typ.count
else:
count = len(typ.tuple_items())
staticarray_offset += 32 * (count - 1)
staticarray_offset += 32 * (get_size_of_type(typ) - 1)

else:
return
Expand Down

0 comments on commit 9d79b10

Please sign in to comment.