coffee-script icon indicating copy to clipboard operation
coffee-script copied to clipboard

Variable redeclared in inner scope

Open taralx opened this issue 12 years ago • 3 comments
trafficstars

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 avatar Feb 16 '13 20:02 taralx

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

taralx avatar Feb 16 '13 20:02 taralx

:+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

alexgorbatchev avatar Jun 30 '13 03:06 alexgorbatchev

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]

davidbau avatar Sep 06 '13 13:09 davidbau