-
Notifications
You must be signed in to change notification settings - Fork 1.7k
CFE allows trailing comma and multiple arguments in extension type representation declaration #53625
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
Do you wish to enforce that there cannot be |
No, I just forgot about metadata. I never use it :) |
AFAIK we don't have |
There is indeed no trailing comma in the current analyzer AST. I mistook the general |
Bug: #53625 Change-Id: I89d34b35b3e8b5977d1f99d550f91ce58e1c2150 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/328340 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]> Reviewed-by: Phil Quitslund <[email protected]>
Bug: #53625 Change-Id: I17994508f2e50c63d656d89e102c8a0d06e45d96 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/329821 Commit-Queue: Konstantin Shcheglov <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
Part of #53625 Part of #49731 Change-Id: I793ef6329d99b1a4e829491f454f42c2ede941b4 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/331185 Commit-Queue: Chloe Stefantsova <[email protected]> Reviewed-by: Johnni Winther <[email protected]>
The current extension type specification proposal does not allow a trailing comma in the representation type declaration.
Example:
The CFE currently allows this, and it should not.
Further, if I add a second argument,
extension type E(int x, int y) {}
, the CFE accepts that too, and also an invocation of it:Or make the paramters optional or named:
Or I can omit the type entirely:
extension type E(x) {} void main() { print(E(42).x); }
prints "42".All this is invalid syntax. While it's nice that the grammar parser allows it, so that we can give better error messages, the syntax should be rejected by a later validation step, preferably still in the parser.
(The analyzer has this validation step. The error given for the trailing comma isn't great,
but for two arguments, or named arguments, an error of
is reasonable. It has some further down-stream errors from not having a valid representation type declaration, which could be quenched.
The analyzer AST model also has a
trailingComma
token in theRepresentationDeclaration
which should always benull
.)If we ever introduce primary constructors in general, with a syntax compatible with extension type declarations, it's likely that the syntax for extension types will be opened up to allow other singleton parameter lists, and trailing commas (and at that point the analyzer AST could give
RepresentationDeclaration
anasPrimaryConstructorParameterList
method).So far then the syntax is restricted to
'(' <metadata> <type> <identifier> ')'
. No more and no less.The text was updated successfully, but these errors were encountered: