Chromium Code Reviews| Index: pkg/compiler/lib/src/resolution/members.dart |
| diff --git a/pkg/compiler/lib/src/resolution/members.dart b/pkg/compiler/lib/src/resolution/members.dart |
| index 652387b9ab146828326a32ce5cdb473311b9a15c..7aa3e1dcdf068bb5d1aceced24f1126deddaa1b7 100644 |
| --- a/pkg/compiler/lib/src/resolution/members.dart |
| +++ b/pkg/compiler/lib/src/resolution/members.dart |
| @@ -2112,6 +2112,9 @@ class ResolverVisitor extends MappingVisitor<ResolutionResult> { |
| * This field is updated when nested closures are visited. |
| */ |
| Element enclosingElement; |
| + |
| + /// Whether we are in a context where `this` is accessible (this will be false |
| + /// in static contexts, factory methods, and field initializers). |
| bool inInstanceContext; |
| bool inCheckContext; |
| bool inCatchBlock; |
| @@ -2304,6 +2307,19 @@ class ResolverVisitor extends MappingVisitor<ResolutionResult> { |
| node, node.source, MessageKind.CANNOT_RESOLVE, |
| {'name': node}); |
| registry.registerThrowNoSuchMethod(); |
| + |
| + // We also report an error within initializers because `this` is |
| + // implicitly accessed when unqualified identifiers are not resolved. |
| + // For details, see section 16.14.3 of the spec (2nd edition): |
| + // An unqualified invocation `i` of the form `id(a1, ...)` |
| + // ... |
| + // If `i` does not occur inside a top level or static function, `i` |
| + // is equivalent to `this.id(a1 , ...)`. |
| + if ((enclosingElement.isInstanceMember && enclosingElement.isField) || |
| + (enclosingElement.isGenerativeConstructor)) { |
| + compiler.reportError( |
|
Johnni Winther
2015/04/10 07:55:50
From a users perspective, it might be better to ha
Siggi Cherem (dart-lang)
2015/04/10 18:56:26
I have it a try. WDYT?
|
| + node, MessageKind.NO_INSTANCE_AVAILABLE, {'name': node.source}); |
| + } |
| } |
| } else if (element.isErroneous) { |
| // Use the erroneous element. |