Skip to content

Commit 3e8af73

Browse files
authored
Merge pull request #1674 from faze-geek/for_loop
Restrict step size 0 in for loop
2 parents c313b33 + a6b46fe commit 3e8af73

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/lpython/semantics/python_ast_to_asr.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4498,6 +4498,10 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
44984498
int64_t inc_int = 1;
44994499
bool is_value_present = ASRUtils::extract_value(inc_value, inc_int);
45004500
if (is_value_present) {
4501+
if (inc_int == 0) {
4502+
throw SemanticError("For loop increment should not be zero.", loc);
4503+
}
4504+
45014505
// Loop end depends upon the sign of m_increment.
45024506
// if inc > 0 then: loop_end -=1 else loop_end += 1
45034507
ASR::binopType offset_op;

0 commit comments

Comments
 (0)