-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
[grammar] comma-related Inconsistency between the spec and implementation. #54538
Comments
Seems like the easiest fix is to change the spec. |
Right, I don't think it's reasonable to introduce a breaking change in order to remove support for trailing commas in in particular situation where it is actually already implemented. One thing, though, does void main() {
for (int i; i < 10; print("foo"), ++i, print("bar"),) {
break;
}
} @munificent, what do you think about trailing commas in |
Wow, I'm a little surprised the formatter doesn't end up inadvertently dropping the trailing comma on the floor. Filed this to track how we want to handle it: dart-lang/dart_style#1354 As far as the language is concerned, it's hard to say. The language doesn't seem to have any consistent principle for where trailing commas are allowed:
I guess for loop updaters are most similar to enum values where there is a closing delimiter, but the stuff inside the delimiter is more than just the comma-separated list of things? In an enum, there may be |
For enums, I'd say there is a trailing delimiter, which is either I agree that the leading and trailing delimiters are not necessarily matched, and for loop increments are like that too, started by Inside that, for-loop increments are more like function arguments, they are comma separated completely general expressions. Currently |
I hope this issue isn't viewed as some evidence that there's "people who depend on this feature". I've discovered this one by accident (it seems that @lrhn discovered it first: dart-lang/language#2430 (comment)!) and I don't plan on ever using it. I wouldn't mind a breaking change that removed this feature to prevent any potential formatter issues. @munificent wrote
|
Consider:
Notice the trailing comma, which, according to the spec, doesn't appear to be valid Dart syntax. However, that program is accepted as a valid dart program by the implementation.
The analyzer and parsers based on Dart.g produce the following parse trees:
Notice how the ANTLR based parser rejects that program, but the analyzer does not.
The text was updated successfully, but these errors were encountered: