Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using a default argument inside an array in a function parameters raises an exception #3745

Closed
asdrubalivan opened this issue Nov 28, 2014 · 1 comment
Labels

Comments

@asdrubalivan
Copy link

The following code in Coffeescript 1.8.0 raises an exception

myFn = (x = 2 ,[a = false, b = 3]) ->

This exception is

TypeError: Cannot read property 'length' of undefined
  at Param.exports.Param.Param.eachName (/usr/lib/node_modules/coffee-script/lib/coffee-script/nodes.js:2049:32)
  at Param.exports.Param.Param.eachName (/usr/lib/node_modules/coffee-script/lib/coffee-script/nodes.js:2052:16)
  at Code.exports.Code.Code.eachParamName (/usr/lib/node_modules/coffee-script/lib/coffee-script/nodes.js:1970:29)
  at Code.exports.Code.Code.compileNode (/usr/lib/node_modules/coffee-script/lib/coffee-script/nodes.js:1927:12)
  at Code.exports.Base.Base.compileToFragments (/usr/lib/node_modules/coffee-script/lib/coffee-script/nodes.js:83:21)
  at Assign.exports.Assign.Assign.compileNode (/usr/lib/node_modules/coffee-script/lib/coffee-script/nodes.js:1628:24)
  at Assign.exports.Base.Base.compileToFragments (/usr/lib/node_modules/coffee-script/lib/coffee-script/nodes.js:83:21)
  at Block.exports.Block.Block.compileNode (/usr/lib/node_modules/coffee-script/lib/coffee-script/nodes.js:381:28)
  at Block.exports.Block.Block.compileWithDeclarations (/usr/lib/node_modules/coffee-script/lib/coffee-script/nodes.js:474:19)
  at Block.exports.Block.Block.compileRoot (/usr/lib/node_modules/coffee-script/lib/coffee-script/nodes.js:446:24)
  at Block.exports.Block.Block.compileToFragments (/usr/lib/node_modules/coffee-script/lib/coffee-script/nodes.js:363:21)
  at Object.<anonymous> (/usr/lib/node_modules/coffee-script/lib/coffee-script/coffee-script.js:49:61)
  at Object.compile (/usr/lib/node_modules/coffee-script/lib/coffee-script/coffee-script.js:34:19)
  at compileScript (/usr/lib/node_modules/coffee-script/lib/coffee-script/command.js:216:33)
  at compilePath (/usr/lib/node_modules/coffee-script/lib/coffee-script/command.js:161:14)
  at Object.exports.run (/usr/lib/node_modules/coffee-script/lib/coffee-script/command.js:96:21)
  at Object.<anonymous> (/usr/lib/node_modules/coffee-script/bin/coffee:7:41)
  at Module._compile (module.js:456:26)
  at Object.Module._extensions..js (module.js:474:10)
  at Module.load (module.js:356:32)
  at Function.Module._load (module.js:312:12)
  at Function.Module.runMain (module.js:497:10)
  at startup (node.js:119:16)
  at node.js:906:3

This also happens if I put a true instead of a false in the code above, but this doesn't happen if I just put numbers like

 myFn = (x = 2 ,[a = 1, b = 3]) ->

I know both examples are syntax errors, but the exception raised by the first one was not expected.

@GeoffreyBooth
Copy link
Collaborator

This compiles just as it looks in CS2:

var myFn;

myFn = function(x = 2, [a = false, b = 3]) {};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants