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
Analyzer problem with map initializers #15565
Comments
Added this to the 1.1 milestone. |
The specification (section 12.11 on This expressions) is unclear about whether this example is allowed or not, so I'm passing this issue on to the language committee. Removed this from the 1.1 milestone. |
The example shown has many errors. I assume the intent was: class Foo { _foo() { Foo() { The issue is that the initializer for the field foo contains a reference to the field bar. The specification says that it is a compile time error if 'this' appears in the initializer of an instance variable. The intent is to cover both explicit and implicit uses of 'this'. The use of _bar is defined to mean this._bar (see the section on identifier reference), which is getter invocation of the implicitly generated getter for the field _bar. I'll clarify that point in the next draft. I'm sending this back to the analyzer; I think the only concern is that only _bar gets flagged but _foo does not (at least in the editor). Note that _foo is a closurization of the _foo method, and again involves this implicitly and is an error. The case of 'baz" is totally different since it occurs in a constructor body, where 'this' is allowed. Removed Area-Language label. |
Removed Priority-Unassigned label. |
Set owner to @stereotype441. |
Fix submitted for review: https://codereview.chromium.org/702623002/ |
Fixed in revision 41478. Added Fixed label. |
Added this to the 1.8 milestone. |
In the following example, there is an error for a closure (key 'bar') that accesses a member of the class if its directly assigned in the initialization. In any of the other locations (keys 'bop' and 'baz') there is no report. I think this is a problem since its surprising / unexpected.
class Foo {
String bar = "hello world";
Map foo = {
'bar': () {
var _bar = bar;
^^^
return _bar;
'bop': _foo
};
_foo() {
var _bar = bar;
return _bar;
}
Foo() {
foo['baz'] = () {
var _bar = bar;
return _bar;
};
}
}
Error message: Only static members can be accessed in initializers.
The text was updated successfully, but these errors were encountered: