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

Compiler crash when await inside variable-free "for [...]" loop

Open davidbau opened this issue 11 years ago • 4 comments
trafficstars

The idiom "for [1..10]" is not supported and causes the iced compiler to crash.

To repro:

for [1..10] await setTimeout defer(), 1000 console.log 'hello'

Expect: 10 hellos, one second apart. Got: "CANNOT CALL METHOD 'INVERT' OF NULL"

Notice, (1) commenting the "await" line makes it work without a delay (2) changing it to "for x in [1..10]" makes it work happily.

davidbau avatar Dec 05 '13 16:12 davidbau

hmm, cool, I didn't even know you could do that in CoffeeScript.

malgorithms avatar Dec 05 '13 16:12 malgorithms

Yeah there are now several issues with how for loops are handled, unfortunately. On Dec 5, 2013 11:44 AM, "Chris Coyne" [email protected] wrote:

hmm, cool, I didn't even know you could do that in CoffeeScript.

— Reply to this email directly or view it on GitHubhttps://github.com/maxtaco/coffee-script/issues/98#issuecomment-29914111 .

maxtaco avatar Dec 05 '13 16:12 maxtaco

Ouch. My students on pencilcode.net have been running into this issue.

Max, any hints or guidance on where in the code to look to fix the problem? Happy to try to contribute a fix if pointed in the right direction.

davidbau avatar Mar 04 '14 17:03 davidbau

Sorry David, life has been crazy with keybase.io launching and us trying to get a beta working. I haven't had any time for anything else, and for this I apologize!

src/nodes.coffee, see class For, method icedCompiledIced. That's where the loop limit rewriting happens. As you can see, it's a full rewrite of the loop constructs since they are split up over mutually recursive functions (for the CSP transform).

The directions for developing are the same as for mainline CoffeeScript (https://github.com/jashkenas/coffee-script/wiki/%5BHowto%5D-Hacking-on-the-CoffeeScript-Compiler) though these directions are a bit out-of-date. Also, I suggest running ./bin/cake rather than the global cake since there are a few iced-aware additions to the Cakefile.

Thanks David, sorry not to be making any progress on these issues.

maxtaco avatar Mar 04 '14 23:03 maxtaco