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

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

Issue 2825813002: Issue 29358. Fix for reporting constant errors while evaluating constructor invocations. (Closed)
Patch Set: Restore TODO. Created 3 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/dart/analysis/driver.dart ('k') | pkg/analyzer/lib/src/error/codes.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/dart/constant/evaluation.dart
diff --git a/pkg/analyzer/lib/src/dart/constant/evaluation.dart b/pkg/analyzer/lib/src/dart/constant/evaluation.dart
index 6243f47f13c8b058261503dc35b691c6d67beebf..9572778d8d7ce6ca98fa058eb9ca9a7d900ab080 100644
--- a/pkg/analyzer/lib/src/dart/constant/evaluation.dart
+++ b/pkg/analyzer/lib/src/dart/constant/evaluation.dart
@@ -550,7 +550,35 @@ class ConstantEvaluationEngine {
}
var fieldMap = new HashMap<String, DartObjectImpl>();
- var fieldInitVisitor = new ConstantVisitor(this, errorReporter,
+
+ // The errors reported while computing values for field initializers, or
+ // default values for the constructor parameters, cannot be reported
+ // into the current ErrorReporter, because they usually happen in a
+ // different source. But they still should cause a constant evaluation
+ // error for the current node.
+ var externalErrorListener = new RecordingErrorListener();
+ var externalErrorReporter =
+ new ErrorReporter(externalErrorListener, constructor.source);
+
+ void reportLocalErrorForRecordedExternalErrors() {
+ ErrorCode errorCode;
+ for (AnalysisError error in externalErrorListener.errors) {
+ if (error.errorCode is CompileTimeErrorCode) {
+ errorCode = CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION;
+ break;
+ }
+ if (error.errorCode is CheckedModeCompileTimeErrorCode) {
+ errorCode =
+ CheckedModeCompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION;
+ break;
+ }
+ }
+ if (errorCode != null) {
+ errorReporter.reportErrorForNode(errorCode, node);
+ }
+ }
+
+ var fieldInitVisitor = new ConstantVisitor(this, externalErrorReporter,
lexicalEnvironment: typeArgumentMap);
// Start with final fields that are initialized at their declaration site.
List<FieldElement> fields = constructor.enclosingElement.fields;
@@ -673,7 +701,7 @@ class ConstantEvaluationEngine {
}
}
ConstantVisitor initializerVisitor = new ConstantVisitor(
- this, errorReporter,
+ this, externalErrorReporter,
lexicalEnvironment: parameterMap);
String superName = null;
NodeList<Expression> superArguments = null;
@@ -712,13 +740,15 @@ class ConstantEvaluationEngine {
// it redirects to.
ConstructorElement constructor = initializer.staticElement;
if (constructor != null && constructor.isConst) {
- return evaluateConstructorCall(
+ DartObjectImpl result = evaluateConstructorCall(
node,
initializer.argumentList.arguments,
constructor,
initializerVisitor,
- errorReporter,
+ externalErrorReporter,
invocation: invocation);
+ reportLocalErrorForRecordedExternalErrors();
+ return result;
}
}
}
@@ -733,9 +763,10 @@ class ConstantEvaluationEngine {
}
evaluateSuperConstructorCall(node, fieldMap, superConstructor,
- superArguments, initializerVisitor, errorReporter);
+ superArguments, initializerVisitor, externalErrorReporter);
}
}
+ reportLocalErrorForRecordedExternalErrors();
return new DartObjectImpl(
definingClass, new GenericState(fieldMap, invocation: invocation));
}
« no previous file with comments | « pkg/analyzer/lib/src/dart/analysis/driver.dart ('k') | pkg/analyzer/lib/src/error/codes.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698