Chromium Code Reviews| 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; |