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

Unified Diff: sdk/lib/_internal/compiler/implementation/resolution/members.dart

Issue 12288041: It's not allowed to have an initializer for a final field that is initialized where it's declared. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 10 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-dart2js.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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));
}
});
« no previous file with comments | « no previous file | tests/co19/co19-dart2js.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698