-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Dart VM: Cascaded calls do not work in class initializer lists #4897
Comments
This comment was originally written by @mhausner Cascaded calls are not legal in field initializer expressions. The language spec says the initializer expression is a conditionalExpression, which does not include cascade sections. If you want cascades in initializer expressions, the grammar has to be changed. Or you can simply write p = (new Stopwatch()..start) |
I see no immediate reason why the RHS of an initializer assignment can't be 'expression', just as for normal assignment. |
Removed Area-VM label. |
Possibly the grammar needs to be changed. We'll see. Added Accepted label. |
The grammar has required a conditionalExpression in that position until now. Even then, there is an ad hoc restriction on function expressions because C(): x = (y) => 3; is ambiguous. If you now support full expressions you need to make sure that C(): x = z = y() => 3; is flagged correctly. I don't think this is worthwhile. We can do something more ad hoc, such as allowing conditionalExpression cascadeSection* in an initializer. Or just use parentheses. |
Per comment 7, changed the grammar so that cascadeExpressions are also allowed in the initializer. Added Done label. |
The following code exposes a bug in the VM parser.
Cascaded calls are legal in class initializer expressions.
//Lars
class X {
Stopwatch p;
X() : p = new Stopwatch()..start();
}
main() => new X();
'Bug.dart': Error: line 3 pos 27: unexpected token '..'
X() : p = new Stopwatch()..start();
^
The text was updated successfully, but these errors were encountered: