Akuli / jou

Yet another programming language
MIT License
11 stars 4 forks source link

Warning for reusing for loop variable #362

Open Akuli opened 1 year ago

Akuli commented 1 year ago

I have multiple times written Jou code like this:

for i = 0; i < 10; i++:
    ...
    for i = 0; i < 10; i++:
        ...

The solution is to rename the variable in one of the loops, but it would be nice if the compiler warned about this.

I'm not sure how I should detect loops like this. Maybe just detect any two nested for loops that start with for foo = bar; ..., where foo parts are the same variable? I don't want to make it too general. For example, this should not trigger the warning:

for i = 0; i < 10; i++:
    ...

for i = 0; i < 10; i++:
    ...