Skip to content

Commit

Permalink
fix: type checking for loops
Browse files Browse the repository at this point in the history
  • Loading branch information
iamdefinitelyahuman committed Jul 5, 2020
1 parent 337c2ef commit b18438b
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions vyper/context/validation/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,12 @@ def visit_For(self, node):
call_node,
)

for_loop_exceptions = []
for type_ in type_list:
# type check the for loop body using each possible type for iterator value
type_ = copy.deepcopy(type_)
type_.is_immutable = True

with self.namespace.enter_scope():
try:
self.namespace[node.target.id] = type_
Expand All @@ -365,10 +368,13 @@ def visit_For(self, node):
try:
for n in node.body:
self.visit(n)
return
return
except TypeMismatch as exc:
if len(type_list) == 1:
raise exc
for_loop_exceptions.append(exc)

if len(set(str(i) for i in for_loop_exceptions)) == 1:
# if every attempt at type checking raised the same exception,
raise for_loop_exceptions[0]

raise TypeMismatch("Could not determine type for iterator values", node)

Expand Down

0 comments on commit b18438b

Please sign in to comment.