From a6b46fe475e3090c90aa68bc9a93b9056f2bfbdb Mon Sep 17 00:00:00 2001 From: faze-geek Date: Fri, 7 Apr 2023 11:00:09 +0530 Subject: [PATCH] check step size 0 --- src/lpython/semantics/python_ast_to_asr.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/lpython/semantics/python_ast_to_asr.cpp b/src/lpython/semantics/python_ast_to_asr.cpp index ddcc6e26f7..999d3edbcd 100644 --- a/src/lpython/semantics/python_ast_to_asr.cpp +++ b/src/lpython/semantics/python_ast_to_asr.cpp @@ -4493,6 +4493,10 @@ class BodyVisitor : public CommonVisitor { 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;