Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(630)

Unified Diff: lib/compiler/implementation/resolver.dart

Issue 10834327: Produce error when duplicate field initializers are found (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: == -> ===, improved test, removed unnecessary "defensive" null checks Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/co19/co19-leg.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 {
« no previous file with comments | « no previous file | tests/co19/co19-leg.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698