Skip to content
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

Allow trailing commas in parameter and argument lists. #26644

Closed
lrhn opened this issue Jun 8, 2016 · 6 comments

Comments

@lrhn
Copy link
Member

commented Jun 8, 2016

To improve the maintainability of long argument and parameter lists, we allow the final argument or parameter to be followed by an optional comma. This allows a style where each argument or parameter is written on a line by itself, and moving one item up or down or between functions doesn't require special handling of the final item.
This matches the existing behavior for list and map literals and enum class declarations.

To be precise:

  • The grammar is changed to allow a single comma right after a final parameter or argument.
  • It does not allow multiple commas between items, a leading comma, or a comma in an empty parameter or argument list.
  • The comma goes before the final ')' in parameter lists with no optional parameters, and before the final '}' or ']' in parameter lists with optional parameters.
  • The comma goes before the final ')' in argument lists.
  • The comma is entirely optional and has no semantic meaning, it's purely a syntactic convenience for a particular style of writing parameter or argument lists.

Tracking bugs for individual tasks:

For later:

@hterkelsen

This comment has been minimized.

Copy link
Member

commented Jun 8, 2016

Can you have a trailing comma after the '}' in a parameter list? eg:

void foo(
    String x,
    List y,
    {bool z: true},
    ) {
}
@lrhn

This comment has been minimized.

Copy link
Member Author

commented Jun 9, 2016

@hterkelsen
Trailing comma after }:
That was not the plan. This is intended for a style where you have one parameter on each line, and multiple parameters, and you can move the individual parameters around among themselves.

It handles the cases where you move the last parameter somewhere else (leaving a dangling comma on the previous line and, maybe, missing a comma after the moved parameter in the new position), or where you add a new last parameter after the existing one (now missing a comma on the previous line).

In your example, you put the single optional parameter on a line including the braces. You can only move that line to the end of another parameter list, so there is no advantage to allowing a comma after it.

Basically the feature is for anywhere where you could write , anotherparameter, but didn't. After the optional parameter brace isn't such a place.

pq added a commit that referenced this issue Jul 1, 2016
Parser support for trailing commas (#26647).
Adds parser support for trailing commas in parameter and argument lists.

Meta-tracking issue: #26644

In most cases, errors were preserved (and tested) across parsers with and without the flag set.  (The exception is a formal paramater list with an extra comma, like `(a,,)` which with trailing comma support enabled only reports a missing identifier; needless to say this is captured in a test and is up for further debate.)

Amazingly (and for better or worse), turning this option on in the parser (`parseTrailingCommas = true`) produces NO errors in the analyzer and server tests.

BUG=26647
R=brianwilkerson@google.com

Review URL: https://codereview.chromium.org/2116853002 .
@sethladd

This comment has been minimized.

Copy link
Member

commented Jul 26, 2016

For the VM and dart2js, do we need to use a flag to opt-in to the feature?

@hterkelsen

This comment has been minimized.

Copy link
Member

commented Jul 27, 2016

No, it should be enabled by default.

On Tue, Jul 26, 2016, 1:18 PM Seth Ladd notifications@github.com wrote:

For the VM and dart2js, do we need to use a flag to opt-in to the feature?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#26644 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AB3uFRov42Of7-BxyL0HYjh0erwUzIpHks5qZkFYgaJpZM4IwrlZ
.

@kevmoo kevmoo added this to the 1.19 milestone Jul 28, 2016

@mit-mit

This comment has been minimized.

Copy link
Member

commented Aug 8, 2016

From discussion in #26649 the style guide update will follow later, and from discussion in release meeting this feature is indeed complete for 1.19, so closing.

@mit-mit mit-mit closed this Aug 8, 2016

@mit-mit

This comment has been minimized.

Copy link
Member

commented Aug 8, 2016

whesse added a commit that referenced this issue Nov 25, 2016
whesse added a commit that referenced this issue Nov 25, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.