-
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
Tear-off: expression is not evaluated to object #24357
Comments
The behavior is what the current grammar specifies:
This means that you can't put a "#foo" after a selector like |
Isn't it a contradiction with Evaluation of a property extraction i of the form e#m proceeds as follows: According this statement getter invocation should be evaluated to the object which is value of the getter |
It's not a contradiction, it just doesn't stand on its own. You have to read that section along with the grammar as @lrhn did above. Consider the analogous: Evaluation of a multiplication expression of the form e0 * e1 proceeds as follows: first the expression e0 is evaluated, then the expression e1 is evaluated, then the result is multiplied. Now, would you expect Edit: to be clear, c.m#g is not a property extraction of the form e#m because it can't be parsed that way. (c.m)#g is a property extraction of the form e#m because that's the way it is parsed. |
Over to Gilad to validate that the VM's approach is correct here. |
What about this? class A {
int m() => 1;
}
A getA() {
return new A();
}
main() {
var f = getA()#m;
} Result: |
|
Ok, thank you for clarification. But I think this grammar is, at least, not obvious at this point and the above is not what Dart user,who is not deeply familiar with the specification and sophisticated syntax like 'primary (selector* | ( ‘#’ ( (identifier ‘=’?) | operator)))', expects. getA().m works, getA()#m not. Why? Why this limited (limited comparing with '.') syntax is needed at all? |
Generalized tear-offs are being removed (#27518) so I don't think we have to worry about this. |
According Dart spec "16.18.3 General Closurization"
"Evaluation of a property extraction i of the form e#m proceeds as follows:
First, the expression e is evaluated to an object o. Then:..."
But in fact expression is not evaluated to object o. Run the following program
Result: error: semicolon expected
var x = c.m#g;
var x = (c.m)#g works well.
Tested on Dart VM version: 1.13.0-dev.2.0 (Tue Sep 8 05:28:05 2015) on "linux_x64"
The text was updated successfully, but these errors were encountered: