Skip to content

Restrict step size 0 in for loop #1674

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -4493,6 +4493,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