-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Lexer: Indenting within object literal produces unexpected behavior, unhelpful error message #2667
Comments
You have no "base" indentation so that's expected. |
I don't think I understand. Shouldn't this work?
|
The first member's indentation is taken as base indent. You can use a =
b: c
D: e |
I personally would expect that to work, especially given that: a = [ foo
bar
baz ] And, more importantly o = { foo
bar
baz } Both work as expected (with or without separator commas). |
Indeed, I understand what works and what not, but I'm questioning this behavior. |
Would work if there weren't implicit objects. The code in question is rewritten as:
and becomes invalid. |
To be clearer this is lexed as a = {b: c
{d: e}
} Whereas |
Ok, makes sense, sorry for the trouble. |
Why closing this? @satyr and @Nami-Doc gave an explanation of why this happens, but i don't think they suggested that it's not a bug, or that it's a nice behavior of the compiler. I think it's an inconsistent behavior and should be considered a bug. At least the confusing error message should be considered a bug IMO: o = { a: 1,
b: 2,
c: 3 } Error: Parse error on line 2: Unexpected '{' WAT? There's no '{' at line 2! That error message is as useful as "Parse error: please move your code around a bit until it parses correctly", which is basically what i'd do in that situation =P |
Fair enough. I fear the parser issue in unfixable, as it would require ignoring indentation generated objects inside others objects. And there's no reason for such a behavior. However, a better error message is needed. |
Something more future-proof would be to display rewritten coffee, maybe |
→ #2160 |
Just chiming in - I've been bitten by this a number of times and there's nothing that I can see that's ambiguous about the syntax. It also makes wrapping objects quite messy unless you're going to list each property on a separate line - which in a number of cases is overkill. |
Is it unreasonable to require { a: b
c: d
} # for ({a: b({c: d})}); ? See from @epidemian's examples that the whitespace is already special cased inside the brackets, because [ a
b ] # works
a()
b() # doesn't I couldn't find an open issue for: { a: b
b: c } # ({a: b({c: d})}); but I argue it should be fixed alongside this. (following #3269; this issue was closed as a duplicate of the error message issue, not the original syntax issue) |
So I meant to write this:
here, and I see I have already asked to get this reopened. Also mentioned here: #1769 (comment) |
Also { a: b,
b: c } should work as well. |
Currently { a: 1
b: 2 } throws
which I believe is correct. The As a general policy I don’t think we should be creating more exceptions where CoffeeScript ignores indentation. We’re a whitespace-significant language, and people just need to get used to that. If you want the keys to start on the same column, just write it like: {
a: 1
b: 2
} |
This code compiles
while this other Syntax Errors
(And generally every time you indent inside a
{}
literal.)Not sure it is a bug, but I can't find why in the docs.
Test it
The text was updated successfully, but these errors were encountered: