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

Unified Diff: pkg/analyzer/lib/src/dart/element/element.dart

Issue 2989243003: Resynthesize values of final fields of classes with const constructors. (Closed)
Patch Set: Created 3 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 | pkg/analyzer/lib/src/kernel/resynthesize.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/dart/element/element.dart
diff --git a/pkg/analyzer/lib/src/dart/element/element.dart b/pkg/analyzer/lib/src/dart/element/element.dart
index 154a8df1af7124e3d9c24827df1658dd886a2ee5..cfbd5165b196556c98ae04d5df10118cabf7c9de 100644
--- a/pkg/analyzer/lib/src/dart/element/element.dart
+++ b/pkg/analyzer/lib/src/dart/element/element.dart
@@ -1018,6 +1018,9 @@ class ClassElementImpl extends AbstractClassElementImpl
return null;
}
+ bool get _hasConstConstructorKernel =>
+ _kernel != null && _kernel.constructors.any((c) => c.isConst);
+
@override
void appendTo(StringBuffer buffer) {
if (isAbstract) {
@@ -2595,8 +2598,8 @@ abstract class ConstVariableElement
Expression get constantInitializer {
if (_constantInitializer == null) {
if (_kernelInitializer != null) {
- _constantInitializer =
- enclosingUnit._kernelContext.getExpression(_kernelInitializer);
+ _constantInitializer = enclosingUnit._kernelContext
+ .getExpression(this, _kernelInitializer);
}
if (_unlinkedConst != null) {
_constantInitializer = enclosingUnit.resynthesizerContext
@@ -4555,7 +4558,8 @@ class FieldElementImpl extends PropertyInducingElementImpl
*/
factory FieldElementImpl.forKernelFactory(
ClassElementImpl enclosingClass, kernel.Field kernel) {
- if (kernel.isConst) {
+ if (kernel.isConst ||
+ kernel.isFinal && enclosingClass._hasConstConstructorKernel) {
return new ConstFieldElementImpl.forKernel(enclosingClass, kernel);
} else {
return new FieldElementImpl.forKernel(enclosingClass, kernel);
@@ -6113,7 +6117,7 @@ abstract class KernelLibraryResynthesizerContext {
/**
* Return the [Expression] for the given kernel.
*/
- Expression getExpression(kernel.Expression expression);
+ Expression getExpression(ElementImpl context, kernel.Expression expression);
/**
* Return the list with exactly two elements - positional and named parameter
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/kernel/resynthesize.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698