Skip to content

Commit

Permalink
fix for semantics
Browse files Browse the repository at this point in the history
  • Loading branch information
tserg committed Nov 13, 2023
1 parent 04ccfa6 commit c10095b
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions vyper/semantics/analysis/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,8 @@ def visit_For(self, node):

validate_expected_type(args[0], IntegerT.any())
type_list = get_common_types(*args)
if not isinstance(args[0], vy_ast.Constant):
arg0_val = args[0]._metadata.get("folded_value")
if not isinstance(arg0_val, vy_ast.Constant):
# range(x, x + CONSTANT)
if not isinstance(args[1], vy_ast.BinOp) or not isinstance(
args[1].op, vy_ast.Add
Expand All @@ -409,18 +410,20 @@ def visit_For(self, node):
)
else:
# range(CONSTANT, CONSTANT)
if not isinstance(args[1], vy_ast.Int):
arg1_val = args[1]._metadata.get("folded_value")
if not isinstance(arg1_val, vy_ast.Int):
raise InvalidType("Value must be a literal integer", args[1])
validate_expected_type(args[1], IntegerT.any())
if args[0].value >= args[1].value:
if arg0_val.value >= arg1_val.value:
raise StructureException("Second value must be > first value", args[1])

if not type_list:
raise TypeMismatch("Iterator values are of different types", node.iter)

else:
# iteration over a variable or literal list
if isinstance(node.iter, vy_ast.List) and len(node.iter.elements) == 0:
iter_val = node.iter._metadata.get("folded_value")
if isinstance(iter_val, vy_ast.List) and len(iter_val.elements) == 0:
raise StructureException("For loop must have at least 1 iteration", node.iter)

type_list = [
Expand Down

0 comments on commit c10095b

Please sign in to comment.