Skip to content

Commit 55ce71b

Browse files
authored
Merge pull request #2309 from iamdefinitelyahuman/fix-list-literals
Fix: incorrect `TypeMismatch` when dealing with literals in lists
2 parents fb9381e + 06ea02a commit 55ce71b

2 files changed

Lines changed: 7 additions & 12 deletions

File tree

tests/parser/types/test_lists.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from vyper.exceptions import ArrayIndexException, TypeMismatch
1+
from vyper.exceptions import ArrayIndexException, OverflowException
22

33

44
def test_list_tester_code(get_contract_with_gas_estimation):
@@ -252,10 +252,10 @@ def test_compile_time_bounds_check(get_contract_with_gas_estimation, assert_comp
252252
code = """
253253
@external
254254
def parse_list_fail():
255-
xs: uint256[3] = [2**255, 1, 3]
255+
xs: uint256[3] = [2**256, 1, 3]
256256
pass
257257
"""
258-
assert_compile_failed(lambda: get_contract_with_gas_estimation(code), TypeMismatch)
258+
assert_compile_failed(lambda: get_contract_with_gas_estimation(code), OverflowException)
259259

260260

261261
def test_2d_array_input_1(get_contract):

vyper/parser/expr.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -938,20 +938,15 @@ def get_out_type(lll_node):
938938
return lll_node.typ
939939

940940
lll_node = []
941-
previous_type = None
942941
out_type = None
943942

944943
for elt in self.expr.elements:
945944
current_lll_node = Expr(elt, self.context).lll_node
946-
if not out_type:
945+
if not out_type or not current_lll_node.typ.is_literal:
946+
# prefer to use a non-literal type here, because literals can be ambiguous
947+
# this should be removed altogether as we refactor types out of parser
947948
out_type = current_lll_node.typ
948-
949-
current_type = get_out_type(current_lll_node)
950-
if len(lll_node) > 0 and previous_type != current_type:
951-
raise TypeMismatch("Lists may only contain one type", self.expr)
952-
else:
953-
lll_node.append(current_lll_node)
954-
previous_type = current_type
949+
lll_node.append(current_lll_node)
955950

956951
return LLLnode.from_list(
957952
["multi"] + lll_node, typ=ListType(out_type, len(lll_node)), pos=getpos(self.expr),

0 commit comments

Comments
 (0)