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

Dart VM: Cascaded calls do not work in class initializer lists #4897

Closed
larsbak opened this issue Sep 4, 2012 · 10 comments
Closed

Dart VM: Cascaded calls do not work in class initializer lists #4897

larsbak opened this issue Sep 4, 2012 · 10 comments
Assignees
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language).
Milestone

Comments

@larsbak
Copy link

larsbak commented Sep 4, 2012

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();
                          ^

@DartBot
Copy link

DartBot commented Sep 4, 2012

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)

@DartBot
Copy link

DartBot commented Sep 7, 2012

This comment was originally written by @mhausner


Added Invalid label.

@larsbak
Copy link
Author

larsbak commented Sep 12, 2012

I'm surprised a cascaded call cannot exist as a class initializer expression.
dart2js and dart_analyzer DO both handle the above case and I do not see any valid reason why the VM should reject the program.
Should be grammar be changed?


Set owner to @gbracha.
Added Triaged label.

@lrhn
Copy link
Member

lrhn commented Sep 12, 2012

I see no immediate reason why the RHS of an initializer assignment can't be 'expression', just as for normal assignment.

@iposva-google
Copy link
Contributor

Removed Area-VM label.
Added Area-Language label.

@gbracha
Copy link
Contributor

gbracha commented Sep 14, 2012

Possibly the grammar needs to be changed. We'll see.


Added Accepted label.

@gbracha
Copy link
Contributor

gbracha commented Sep 20, 2012

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.

@gbracha
Copy link
Contributor

gbracha commented Oct 15, 2012

Removed this from the M1 milestone.
Added this to the M2 milestone.

@gbracha
Copy link
Contributor

gbracha commented Nov 26, 2012

Per comment 7, changed the grammar so that cascadeExpressions are also allowed in the initializer.


Added Done label.

@gbracha
Copy link
Contributor

gbracha commented Nov 26, 2012

Bugs:

dart2js: issue #6953.
VM: issue #6954.
Analyzer: issue #6955

@larsbak larsbak added Type-Defect area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). labels Nov 26, 2012
@larsbak larsbak added this to the M2 milestone Nov 26, 2012
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language).
Projects
None yet
Development

No branches or pull requests

6 participants