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

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

Issue 637303005: Type check constant variable declarations. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 2 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/generated/error.dart » ('j') | pkg/analyzer/lib/src/generated/error.dart » ('J')
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 37cece34f4e2c7ce670c5c89f68e8fde9b144429..8c1720693f5b9daea258a4206324362765433f12 100644
--- a/pkg/analyzer/lib/src/generated/constant.dart
+++ b/pkg/analyzer/lib/src/generated/constant.dart
@@ -545,10 +545,17 @@ class ConstantValueComputer {
beforeComputeValue(constNode);
if (constNode is VariableDeclaration) {
VariableDeclaration declaration = constNode;
- Element element = declaration.element;
+ VariableElement element = declaration.element;
RecordingErrorListener errorListener = new RecordingErrorListener();
ErrorReporter errorReporter = new ErrorReporter(errorListener, element.source);
DartObjectImpl dartObject = declaration.initializer.accept(createConstantVisitor(errorReporter));
+ if (dartObject != null) {
+ if (!dartObject.isNull && !dartObject.type.isSubtypeOf(element.type)) {
+ errorReporter.reportErrorForNode(
+ CheckedModeCompileTimeErrorCode.VARIABLE_TYPE_MISMATCH,
+ declaration, [dartObject.type, element.type]);
+ }
+ }
(element as VariableElementImpl).evaluationResult = new EvaluationResultImpl.con2(dartObject, errorListener.errors);
} else if (constNode is InstanceCreationExpression) {
InstanceCreationExpression expression = constNode;
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/generated/error.dart » ('j') | pkg/analyzer/lib/src/generated/error.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698