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
Update map literal formatting test #725
Conversation
@@ -248,9 +248,9 @@ someVeryLongTargetFunction( | |||
element | |||
].someLongMethod(); | |||
>>> do not split on "." when target is map | |||
{"key": "value", "another": "another value"}.someLongMethod(); | |||
<String,String>{"key": "value", "another": "another value"}.someLongMethod(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this change necessary? The expression in the expression statement isn't a map literal, it's a method invocation (.someLongMethod()
) whose receiver is a map literal. Is that not valid?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the change is necessary.
No, the expression statement is not valid.
Although it's valid as an expression, it's not valid as an expression statement.
The problem is that the statement begins with {
and to the parser when it's parsing a statement, the {
looks like the start of a block. When parsing a statement (not an expression), if the parser supported {
as either a block or an expression statement, then it would have an arbitrarily long lookahead to figure out if the thing after the {
was an expression followed by a :
and only then would it be able to decide whether to parse the {
as a block or an expression statement.
The spec has the clause above so that the parser does not have an arbitrarily long lookahead (and possible ambiguity) each time it parsed a statement beginning with {
.
@leafpetersen @lrhn For clarification of the spec. |
The spec language doesn't seem to me to cover this case. As best as I can tell, none of our release mode compilers (dart2js, dart) support this or any related things that I've tests (cascade, subscript, update), so I think it would be de facto non-breaking to make the spec reflect what seems to be the intention. That is:
Should probably be:
|
@munificent Do you mind if this gets landed to unblock the analyzer/parser integration? We'll have to sort out the spec decision and if necessary all of the implementations separately, and I don't see any reason to block on this now. |
@leafpetersen your understanding aligns with mine on the spec. I'm happy to change the test to match the intention of the spec. |
We should specify what the implementations do. The grammar works either way - if a block ends with Allowing leading maps does make parsing need arbitrary look-ahead to determine whether something starting with So, the simplest is to just keep the current CFEbehavior and codify it in the spec. |
@munificent Thanks! We also need the updated version of dart_style to be pulled into the SDK. Could you publish it and update the DEPS file to bring it it? |
For the record, in SDK 1.13 (which is before the VM and the dart2js switched to the CFE, I believe), all of these examples were rejected by the VM and dart2js: void main() {
{"foo" : "bar"}.containsKey("foo");
{"foo" : "bar"}..containsKey("foo");
{"foo" : "bar"}["foo"];
{"foo" : "bar"}["foo"] = "baz";
} |
Then I see no problem in keeping them disallowed, let's just do that. I'll fix the specification. |
This test case is invalid Dart syntax that the old analyzer parser let slide by.
From section 17.2 of the language spec...