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

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

Issue 1175073002: Report a compile-time error if a const field is multiply initialized. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 6 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/test/generated/compile_time_error_code_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 9cf3a6cc1fd2003759b35ff8f137e0d608bfd392..6e157fccf8bde622fe464829ccaaa0b492e1ca0f 100644
--- a/pkg/analyzer/lib/src/generated/constant.dart
+++ b/pkg/analyzer/lib/src/generated/constant.dart
@@ -747,6 +747,10 @@ class ConstantEvaluationEngine {
}
}
String fieldName = field.name;
+ if (fieldMap.containsKey(fieldName)) {
+ errorReporter.reportErrorForNode(
+ CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, node);
+ }
fieldMap[fieldName] = argumentValue;
}
} else {
@@ -768,6 +772,10 @@ class ConstantEvaluationEngine {
initializerExpression.accept(initializerVisitor);
if (evaluationResult != null) {
String fieldName = constructorFieldInitializer.fieldName.name;
+ if (fieldMap.containsKey(fieldName)) {
+ errorReporter.reportErrorForNode(
+ CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, node);
+ }
fieldMap[fieldName] = evaluationResult;
PropertyAccessorElement getter = definingClass.getGetter(fieldName);
if (getter != null) {
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/compile_time_error_code_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698