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

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

Issue 1493833003: Issue 25050. Fix for NPE in ConstantEvaluationEngine when duplicate fields. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years 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/test/src/task/dart_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/constant.dart
diff --git a/pkg/analyzer/lib/src/generated/constant.dart b/pkg/analyzer/lib/src/generated/constant.dart
index 24125064171085e4cfad5f3679f3da5839bd62cb..8638c848cbf3751fa1d4e30841fbdc09e8b94b29 100644
--- a/pkg/analyzer/lib/src/generated/constant.dart
+++ b/pkg/analyzer/lib/src/generated/constant.dart
@@ -704,6 +704,13 @@ class ConstantEvaluationEngine {
field is ConstFieldElementImpl) {
validator.beforeGetFieldEvaluationResult(field);
EvaluationResultImpl evaluationResult = field.evaluationResult;
+ // It is possible that the evaluation result is null.
+ // This happens for example when we have duplicate fields.
+ // class Test {final x = 1; final x = 2; const Test();}
+ if (evaluationResult == null) {
+ continue;
+ }
+ // Match the value and the type.
DartType fieldType =
FieldMember.from(field, constructor.returnType).type;
DartObjectImpl fieldValue = evaluationResult.value;
@@ -713,7 +720,7 @@ class ConstantEvaluationEngine {
node,
[fieldValue.type, field.name, fieldType]);
}
- fieldMap[field.name] = evaluationResult.value;
+ fieldMap[field.name] = fieldValue;
}
}
// Now evaluate the constructor declaration.
« no previous file with comments | « no previous file | pkg/analyzer/test/src/task/dart_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698