From b18438be96b7551be16cfb6e6c842a42f4ceb7e0 Mon Sep 17 00:00:00 2001 From: Ben Hauser Date: Sun, 5 Jul 2020 14:58:27 +0400 Subject: [PATCH] fix: type checking for loops --- vyper/context/validation/local.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/vyper/context/validation/local.py b/vyper/context/validation/local.py index d7ce85ee9d..539002c2a8 100644 --- a/vyper/context/validation/local.py +++ b/vyper/context/validation/local.py @@ -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_ @@ -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)