Skip to content

Commit

Permalink
Merge pull request lcompilers#1674 from faze-geek/for_loop
Browse files Browse the repository at this point in the history
Restrict step size 0 in for loop
  • Loading branch information
certik authored Apr 7, 2023
2 parents c313b33 + a6b46fe commit 3e8af73
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/lpython/semantics/python_ast_to_asr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4498,6 +4498,10 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
int64_t inc_int = 1;
bool is_value_present = ASRUtils::extract_value(inc_value, inc_int);
if (is_value_present) {
if (inc_int == 0) {
throw SemanticError("For loop increment should not be zero.", loc);
}

// Loop end depends upon the sign of m_increment.
// if inc > 0 then: loop_end -=1 else loop_end += 1
ASR::binopType offset_op;
Expand Down

0 comments on commit 3e8af73

Please sign in to comment.