maxtaco / coffee-script

IcedCoffeeScript
http://maxtaco.github.com/coffee-script
MIT License
727 stars 58 forks source link

Variable redeclared in inner scope #62

Open taralx opened 11 years ago

taralx commented 11 years ago

Input: -> v = '' -> loop await f defer v

Expected result: "var v" only appears at top of function. Actual result: "var v" appears at top of function and inside loop.

taralx commented 11 years ago
->
  v = ''
  -> loop
    await f defer v
alexgorbatchev commented 11 years ago

:+1: same expectation here... have to create an intermediate variable to get around this :( here's even more trivial example

user = null

foo = ->
    await foo '...', defer user
davidbau commented 11 years ago

Agreed that variables should not be shadowed because of use in defer. Just ran into this as well.

val = 10
do ->
  console.log val
  await read defer val

Expect: should write 10. Commenting the await line writes 10.

The code below works as expected.

aval = [10]
do ->
  console.log aval[0]
  await read defer aval[0]