Chromium Code Reviews| Index: sdk/lib/_internal/compiler/implementation/resolution/members.dart |
| =================================================================== |
| --- sdk/lib/_internal/compiler/implementation/resolution/members.dart (revision 18617) |
| +++ sdk/lib/_internal/compiler/implementation/resolution/members.dart (working copy) |
| @@ -936,7 +936,7 @@ |
| bool hasSuper; |
| InitializerResolver(this.visitor) |
| - : initialized = new Map<SourceString, Node>(), hasSuper = false; |
| + : initialized = new Map<Element, Node>(), hasSuper = false; |
| error(Node node, MessageKind kind, [arguments = const {}]) { |
| visitor.error(node, kind, arguments); |
| @@ -953,13 +953,21 @@ |
| return node.receiver.asIdentifier().isThis(); |
| } |
| - void checkForDuplicateInitializers(SourceString name, Node init) { |
| - if (initialized.containsKey(name)) { |
| + void checkForDuplicateInitializers(Element field, Node init) { |
| + SourceString name = field.name; |
| + if (initialized.containsKey(field)) { |
| + warning(initialized[field], MessageKind.ALREADY_INITIALIZED, |
|
ahe
2013/02/19 10:58:10
This is not optimal. See if you can use something
ngeoffray
2013/02/19 11:18:10
Done.
|
| + {'fieldName': name}); |
| error(init, MessageKind.DUPLICATE_INITIALIZER, {'fieldName': name}); |
| - warning(initialized[name], MessageKind.ALREADY_INITIALIZED, |
| - {'fieldName': name}); |
| + } else if (field.modifiers.isFinal()) { |
| + Node fieldNode = field.parseNode(visitor.compiler).asSendSet(); |
|
ahe
2013/02/19 10:58:10
Why asSendSet?
ngeoffray
2013/02/19 11:18:10
Because that's how we know the field is initialize
ahe
2013/02/19 11:46:07
Sorry, I misread the code.
|
| + if (fieldNode != null) { |
| + warning(fieldNode, MessageKind.ALREADY_INITIALIZED, |
| + {'fieldName': name}); |
| + error(init, MessageKind.DUPLICATE_INITIALIZER, {'fieldName': name}); |
| + } |
| } |
| - initialized[name] = init; |
| + initialized[field] = init; |
| } |
| void resolveFieldInitializer(FunctionElement constructor, SendSet init) { |
| @@ -982,7 +990,7 @@ |
| } |
| visitor.useElement(init, target); |
| visitor.world.registerStaticUse(target); |
| - checkForDuplicateInitializers(name, init); |
| + checkForDuplicateInitializers(target, init); |
| // Resolve initializing value. |
| visitor.visitInStaticContext(init.arguments.head); |
| } |
| @@ -1121,7 +1129,8 @@ |
| constructor.computeSignature(visitor.compiler); |
| functionParameters.forEachParameter((Element element) { |
| if (identical(element.kind, ElementKind.FIELD_PARAMETER)) { |
| - checkForDuplicateInitializers(element.name, |
| + FieldParameterElement fieldParameter = element; |
| + checkForDuplicateInitializers(fieldParameter.fieldElement, |
| element.parseNode(visitor.compiler)); |
| } |
| }); |