| Index: lib/compiler/implementation/resolver.dart
|
| diff --git a/lib/compiler/implementation/resolver.dart b/lib/compiler/implementation/resolver.dart
|
| index aff2ad7514ac706518559708544f85e8f670c237..6aa99c43b383c6696abbd27879ca7b90631c49e5 100644
|
| --- a/lib/compiler/implementation/resolver.dart
|
| +++ b/lib/compiler/implementation/resolver.dart
|
| @@ -429,6 +429,14 @@ class InitializerResolver {
|
| return node.receiver.asIdentifier().isThis();
|
| }
|
|
|
| + void checkForDuplicateInitializers(SourceString name, Node init) {
|
| + if (initialized.containsKey(name)) {
|
| + error(init, MessageKind.DUPLICATE_INITIALIZER, [name]);
|
| + warning(initialized[name], MessageKind.ALREADY_INITIALIZED, [name]);
|
| + }
|
| + initialized[name] = init;
|
| + }
|
| +
|
| void resolveFieldInitializer(FunctionElement constructor, SendSet init) {
|
| // init is of the form [this.]field = value.
|
| final Node selector = init.selector;
|
| @@ -449,12 +457,7 @@ class InitializerResolver {
|
| error(init, MessageKind.INVALID_RECEIVER_IN_INITIALIZER);
|
| }
|
| visitor.useElement(init, target);
|
| - // Check for duplicate initializers.
|
| - if (initialized.containsKey(name)) {
|
| - error(init, MessageKind.DUPLICATE_INITIALIZER, [name]);
|
| - warning(initialized[name], MessageKind.ALREADY_INITIALIZED, [name]);
|
| - }
|
| - initialized[name] = init;
|
| + checkForDuplicateInitializers(name, init);
|
| // Resolve initializing value.
|
| visitor.visitInStaticContext(init.arguments.head);
|
| }
|
| @@ -552,6 +555,17 @@ class InitializerResolver {
|
| */
|
| FunctionElement resolveInitializers(FunctionElement constructor,
|
| FunctionExpression functionNode) {
|
| + // Keep track of all "this.param" parameters specified for constructor so
|
| + // that we can ensure that fields are initialized only once.
|
| + FunctionSignature functionParameters =
|
| + constructor.computeSignature(visitor.compiler);
|
| + functionParameters.forEachParameter((Element element) {
|
| + if (element.kind === ElementKind.FIELD_PARAMETER) {
|
| + checkForDuplicateInitializers(element.name,
|
| + element.parseNode(visitor.compiler));
|
| + }
|
| + });
|
| +
|
| if (functionNode.initializers === null) {
|
| initializers = const EmptyLink<Node>();
|
| } else {
|
|
|