CoffeeScriptRedux icon indicating copy to clipboard operation
CoffeeScriptRedux copied to clipboard

Conditional assignment broken

Open mcculloughsean opened this issue 12 years ago • 4 comments

records = [undefined, {default: false}, {default: true}]
records[0]?.default = true
if records[0]? then records[0].default = true 

the last two lines should do the same thing, but the first line causes the compiler to return compile: assignment: unassignable assignee: ConditionalExpression

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/2268312-conditional-assignment-broken?utm_campaign=plugin&utm_content=tracker%2F33145&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F33145&utm_medium=issues&utm_source=github).

mcculloughsean avatar Sep 25 '13 20:09 mcculloughsean

Is

records[0]?.default = true

a correct CoffeeScript expression?

I can't find any lvalue-?. expression on http://coffeescript.org/ ... which IMO matches the error message which basically says Hey, that expr you used as lvalue is an rvalue only

ulikoehler avatar Sep 29 '13 13:09 ulikoehler

Yes, it's a correct CoffeeScript expression. Basically everything in coffee is an expression. The tutorial doesn't talk about lvalue or rvalue because there's no point in making simple stuff complex.

vendethiel avatar Sep 29 '13 13:09 vendethiel

Edit: I misunderstood the problem :( Basically you want ? soaking to capture the full assignment expression, not just the access.

~~The problem is records[0]?.default evaluates to the equivalent of records[0] != null ? records[0].default : undefined - so what you are trying to write is something like (records[0] != null ? records[0].default : undefined) = true, which doesn't make sense (certainly not in the alternative branch).~~

~~You probably could give conditional expressions assignable semantics, but it doesn't feel like that is something coffeescript should do, since it's not clear what records[0] should be such that default can be set on it (e.g. when you write records[0]?.default = true, should records[0] become a vanilla object? Why not a string or number or function or prototyped object?).~~

connec avatar Sep 29 '13 19:09 connec

+1 for this issue.

vivinjoy avatar Oct 13 '13 11:10 vivinjoy