Skip to content
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

Restrict step size 0 in for loop #1674

Merged
merged 1 commit into from
Apr 7, 2023
Merged

Conversation

faze-geek
Copy link
Contributor

On master :

def f():
    i:i32 = 0
    for i in range(1,5,0):
        print(i)
    
f()

(lp) C:\Users\kunni\lpython>python try.py
Traceback (most recent call last):
  File "C:\Users\kunni\lpython\try.py", line 6, in <module>
    f()
  File "C:\Users\kunni\lpython\try.py", line 3, in f
    for i in range(1,5,0):
ValueError: range() arg 3 must not be zero

(lp) C:\Users\kunni\lpython>src\bin\lpython try.py
1
1
1
1
.... #Goes into infinite loop

On branch :

(lp) C:\Users\kunni\lpython>src\bin\lpython try.py
semantic error: For loop increment should not be zero.
 --> try.py:3:5 - 4:16
  |
3 |        for i in range(1,5,0):
  |        ^^^^^^^^^^^^^^^^^^^^^^...

@faze-geek
Copy link
Contributor Author

This is ready for reviews.

@czgdp1807
Copy link
Collaborator

This makes sense but should be merged only after libasr sync is complete.

@certik certik merged commit 3e8af73 into lcompilers:main Apr 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants