Skip to content

Commit

Permalink
Fix typecheck for tuple returns
Browse files Browse the repository at this point in the history
The calls to make_setter did not have the destination type set
correctly.
Fixes #1006
  • Loading branch information
charles-cooper committed Jan 4, 2019
1 parent ba87f5b commit f76897e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
11 changes: 11 additions & 0 deletions tests/parser/functions/test_return_tuple.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from vyper.exceptions import TypeMismatchException

def test_return_type(get_contract_with_gas_estimation):
long_string = 35 * "test"

Expand Down Expand Up @@ -113,3 +115,12 @@ def test() -> (int128, bytes[20], address, bytes[20]):
c = get_contract_with_gas_estimation(code)

assert c.out_literals() == [1, b"testtesttest", None, b"random"]

def test_tuple_return_typecheck(assert_tx_failed, get_contract_with_gas_estimation):
code = """
@public
def getTimeAndBalance() -> (bool, address):
return block.timestamp, self.balance
"""

assert_tx_failed(lambda: get_contract_with_gas_estimation(code), TypeMismatchException)
5 changes: 4 additions & 1 deletion vyper/parser/parser_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,10 @@ def increment_dynamic_offset(dynamic_spot):
['mload', dynamic_offset_counter]]
]

items = sub.typ.tuple_items()
if not isinstance(context.return_type, TupleLike):
raise TypeMismatchException('Trying to return %r when expecting %r' % (sub.typ, context.return_type), getpos(stmt))
items = context.return_type.tuple_items()

dynamic_offset_start = 32 * len(items) # The static list of args end.

for i, (key, typ) in enumerate(items):
Expand Down

0 comments on commit f76897e

Please sign in to comment.