jashkenas / coffeescript

Unfancy JavaScript
https://coffeescript.org/
MIT License
16.52k stars 1.98k forks source link

With enough for loops CoffeeScript will generate ‘do’ as a variable name #4267

Closed eelco closed 8 years ago

eelco commented 8 years ago

To reproduce:

noop = ->
xs = []

for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()
for x in xs
    noop()

Expected:

Observed:

lydell commented 8 years ago

Wow, that’s a really funny bug! Good catch! :)

vendethiel commented 8 years ago

Good one indeed. @lydell would it make sense to always have a numeric suffix to generated variable names instead?

lydell commented 8 years ago

@vendethiel It’s nice, though, to first get i, then j, then k … perhaps one could switch to i1, i2, etc. (like you suggest) when we run out of single-char names?

vendethiel commented 8 years ago

That'd be fine as well, I think.

lydell commented 8 years ago

@eelco Out of curiosity, how did you even find this? :)

eelco commented 8 years ago

@lydell I’m a product engineer at Framer and was trying to help a customer who made a really big prototype and did not understand how it suddenly stopped working when he added another for-loop 😄