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

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

Issue 649733002: Check field type when evaluating initializing formals. (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/element.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 0f7d0cdc3e3d07df89fb64f12f2731129e3ee0c4..37cece34f4e2c7ce670c5c89f68e8fde9b144429 100644
--- a/pkg/analyzer/lib/src/generated/constant.dart
+++ b/pkg/analyzer/lib/src/generated/constant.dart
@@ -733,8 +733,21 @@ class ConstantValueComputer {
[argumentValue.type, parameter.type]);
}
if (baseParameter.isInitializingFormal) {
- FieldElement field = (baseParameter as FieldFormalParameterElement).field;
+ FieldElement field = (parameter as FieldFormalParameterElement).field;
if (field != null) {
+ DartType fieldType = field.type;
+ if (fieldType != parameter.type) {
+ // We've already checked that the argument can be assigned to the
+ // parameter; we also need to check that it can be assigned to
+ // the field.
+ if (!argumentValue.isNull &&
+ !argumentValue.type.isSubtypeOf(fieldType)) {
+ errorReporter.reportErrorForNode(
+ CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH,
+ errorTarget,
+ [argumentValue.type, fieldType]);
+ }
+ }
String fieldName = field.name;
fieldMap[fieldName] = argumentValue;
}
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/generated/element.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698