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

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

Issue 644283002: Type check field assignments during constant evaluation. (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') | 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 8c1720693f5b9daea258a4206324362765433f12..d47db7daaf6125ff5af6684f9e86da752f15333a 100644
--- a/pkg/analyzer/lib/src/generated/constant.dart
+++ b/pkg/analyzer/lib/src/generated/constant.dart
@@ -775,6 +775,14 @@ class ConstantValueComputer {
if (evaluationResult != null) {
String fieldName = constructorFieldInitializer.fieldName.name;
fieldMap[fieldName] = evaluationResult;
+ PropertyAccessorElement getter = definingClass.getGetter(fieldName);
Brian Wilkerson 2014/10/12 20:20:42 Seems like we should need to check for "getter !=
Paul Berry 2014/10/13 15:55:33 That's a good point. I'll add tests for these cas
+ PropertyInducingElement field = getter.variable;
+ if (!evaluationResult.isNull &&
+ !evaluationResult.type.isSubtypeOf(field.type)) {
+ errorReporter.reportErrorForNode(
+ CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_FIELD_TYPE_MISMATCH,
+ node, [evaluationResult.type, fieldName, field.type]);
+ }
}
} else if (initializer is SuperConstructorInvocation) {
SuperConstructorInvocation superConstructorInvocation = initializer;
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/generated/error.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698