Skip to content

Commit a6b46fe

Browse files
committed
check step size 0
1 parent b35e744 commit a6b46fe

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
@@ -4493,6 +4493,10 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
44934493
int64_t inc_int = 1;
44944494
bool is_value_present = ASRUtils::extract_value(inc_value, inc_int);
44954495
if (is_value_present) {
4496+
if (inc_int == 0) {
4497+
throw SemanticError("For loop increment should not be zero.", loc);
4498+
}
4499+
44964500
// Loop end depends upon the sign of m_increment.
44974501
// if inc > 0 then: loop_end -=1 else loop_end += 1
44984502
ASR::binopType offset_op;

0 commit comments

Comments
 (0)