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

Unified Diff: pkg/analyzer/lib/src/generated/resolver.dart

Issue 1099953004: In constant evaluation, handle final vars initialized at declaration site. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 8 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 | « pkg/analyzer/lib/src/generated/element.dart ('k') | pkg/analyzer/test/generated/all_the_rest_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/generated/resolver.dart
diff --git a/pkg/analyzer/lib/src/generated/resolver.dart b/pkg/analyzer/lib/src/generated/resolver.dart
index 926244b5c090a74cbdfd43448b684d4ccdb25d35..ed9ea4080f41c9812f5b7c62f3dacf153a6bfbbd 100644
--- a/pkg/analyzer/lib/src/generated/resolver.dart
+++ b/pkg/analyzer/lib/src/generated/resolver.dart
@@ -3062,7 +3062,7 @@ class ElementBuilder extends RecursiveAstVisitor<Object> {
if (_inFieldContext) {
SimpleIdentifier fieldName = node.name;
FieldElementImpl field;
- if (isConst && hasInitializer) {
+ if ((isConst || isFinal) && hasInitializer) {
field = new ConstFieldElementImpl.con1(fieldName);
} else {
field = new FieldElementImpl.forNode(fieldName);
@@ -11305,8 +11305,17 @@ class ResolverVisitor extends ScopedVisitor {
@override
Object visitVariableDeclaration(VariableDeclaration node) {
super.visitVariableDeclaration(node);
- if (node.element.isConst && node.initializer != null) {
- (node.element as ConstVariableElement).constantInitializer =
+ VariableElement element = node.element;
+ // Note: in addition to cloning the initializers for const variables, we
+ // have to clone the initializers for non-static final fields (because if
+ // they occur in a class with a const constructor, they will be needed to
+ // evaluate the const constructor).
Brian Wilkerson 2015/04/22 02:44:00 Do we really need the AST structure? The initializ
Paul Berry 2015/04/24 18:06:33 (Capturing the result of an in-person discussion)
+ if ((element.isConst ||
+ (element is FieldElement &&
+ element.isFinal &&
+ !element.isStatic)) &&
+ node.initializer != null) {
+ (element as ConstVariableElement).constantInitializer =
new ConstantAstCloner().cloneNode(node.initializer);
}
return null;
« no previous file with comments | « pkg/analyzer/lib/src/generated/element.dart ('k') | pkg/analyzer/test/generated/all_the_rest_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698