-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Parsing in tools and spec disagree #26602
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
Comments
Since all tools agree, this should maybe be addressed by the spec, disallowing it. |
I couldn't find any text in the spec explaining why, but analyzer has an explicit test in order to disallow exactly this case, with the following un-helpful comment:
|
I believe the problem is that the grammar is harder to parse if you allow unparenthesized function literals. C(y) : x = (y) { print(y); }; You can't see whether We should either specify the restriction: initializer list expressions must not contain something that looks like a constructor body - however we say that, fx anything is allowed if it's parenthesized because then we know it's not the constructor body, so it's not just "no functions expressions in initializers". Alternatively we just accept the current grammar and make the parsers match it. I think the VM parser may be the biggest challenge because they try hard to be look-ahead-1. Dart2JS should not have a problem since it matches braces while tokenizing so it can quickly check the token after the closing brace before determining the next step. |
@lrhn Thanks for reminding me why this was disallowed. Analyzer also does brace matching during tokenization, and could use the same technique. However, allowing this would also have implications for recovery in the face of certain errors (such as a missing semicolon). I don't believe that the problem is insurmountable, but we should take it into account when deciding what to do. |
Speculatively moving this to area-specification on the hunch that what we already implemented is what we want and that we should tweak the spec to follow it. If we end up deciding otherwise, we can retarget this. |
No milestone now: This correction is part of a larger update of grammar related parts of the specification, based on Dart.g. |
Closing, the language specification is being updated to include the restriction in this PR: dart-lang/language#866. |
According to the grammar fragments in the language specification (v. 1.11), we can derive as follows (where
A
stands for a construct that we need not worry about because it may be omitted or it is one or more unchosen alternatives):This shows that a
fieldInitializer
can bex = () { y = 3; }
.Yet, the following program is rejected during parsing:
This applies to
dart
,dart2js
, anddartanalyzer
, all in version 1.17.0-dev.6.0.The text was updated successfully, but these errors were encountered: