| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library dart2js.resolution.constructors; | 5 library dart2js.resolution.constructors; |
| 6 | 6 |
| 7 import '../common.dart'; | 7 import '../common.dart'; |
| 8 import '../common/resolution.dart' show Resolution; | 8 import '../common/resolution.dart' show Resolution; |
| 9 import '../constants/constructors.dart' | 9 import '../constants/constructors.dart' |
| 10 show | 10 show |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 } | 91 } |
| 92 | 92 |
| 93 void resolveFieldInitializer(SendSet init) { | 93 void resolveFieldInitializer(SendSet init) { |
| 94 // init is of the form [this.]field = value. | 94 // init is of the form [this.]field = value. |
| 95 final Node selector = init.selector; | 95 final Node selector = init.selector; |
| 96 final String name = selector.asIdentifier().source; | 96 final String name = selector.asIdentifier().source; |
| 97 // Lookup target field. | 97 // Lookup target field. |
| 98 Element target; | 98 Element target; |
| 99 FieldElement field; | 99 FieldElement field; |
| 100 if (isFieldInitializer(init)) { | 100 if (isFieldInitializer(init)) { |
| 101 target = constructor.enclosingClass.lookupLocalMember(name); | 101 // Use [enclosingElement] instead of [enclosingClass] to ensure lookup in |
| 102 // patch class when necessary. |
| 103 ClassElement cls = constructor.enclosingElement; |
| 104 target = cls.lookupLocalMember(name); |
| 102 if (target == null) { | 105 if (target == null) { |
| 103 reporter.reportErrorMessage( | 106 reporter.reportErrorMessage( |
| 104 selector, MessageKind.CANNOT_RESOLVE, {'name': name}); | 107 selector, MessageKind.CANNOT_RESOLVE, {'name': name}); |
| 105 target = new ErroneousFieldElementX( | 108 target = new ErroneousFieldElementX( |
| 106 selector.asIdentifier(), constructor.enclosingClass); | 109 selector.asIdentifier(), constructor.enclosingClass); |
| 107 } else if (target.kind != ElementKind.FIELD) { | 110 } else if (target.kind != ElementKind.FIELD) { |
| 108 reporter.reportErrorMessage( | 111 reporter.reportErrorMessage( |
| 109 selector, MessageKind.NOT_A_FIELD, {'fieldName': name}); | 112 selector, MessageKind.NOT_A_FIELD, {'fieldName': name}); |
| 110 target = new ErroneousFieldElementX( | 113 target = new ErroneousFieldElementX( |
| 111 selector.asIdentifier(), constructor.enclosingClass); | 114 selector.asIdentifier(), constructor.enclosingClass); |
| (...skipping 770 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 882 // constructors. | 885 // constructors. |
| 883 return null; | 886 return null; |
| 884 } | 887 } |
| 885 // TODO(johnniwinther): Use [Name] for lookup. | 888 // TODO(johnniwinther): Use [Name] for lookup. |
| 886 ConstructorElement constructor = cls.lookupConstructor(constructorName); | 889 ConstructorElement constructor = cls.lookupConstructor(constructorName); |
| 887 if (constructor != null) { | 890 if (constructor != null) { |
| 888 constructor = constructor.declaration; | 891 constructor = constructor.declaration; |
| 889 } | 892 } |
| 890 return constructor; | 893 return constructor; |
| 891 } | 894 } |
| OLD | NEW |