Wiki

Ticket #246 (new enhancement)

Opened 14 years ago

warn on overwriting variable as a for loop's variable

Reported by: Kurper Owned by:
Priority: trivial Milestone:
Component: Cobra Compiler Version: 0.8.0
Keywords: Cc:

Description

This produces no warning:
def f(i as int)

for i in [0, 1]

print i

print i # it's 1, whoops!

In C#, you'd get an error if you did "for(int i = 0; ...", so falling back on C# as a warning mechanism for this doesn't really work. I don't know whether other people do silly things like this more often than people want to make a for loop's variable have a wider scope than the loop itself. Just warning on using parameters in this way, rather than any variable, would have done the trick in the code that made me submit this ticket, and would probably lead to less false positives, if that's an issue.

<kurper-> <kurper> <kurper-> think that should be a warning?
<kurper-> <kurper> <kurper-> its not an issue in c# cause you don't have implicit variable declarations, so the "let c# do the warnings" strategy doesnt work

Note: See TracTickets for help on using tickets.