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

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

Issue 650323003: Allow analyzer to distinguish unresolved types from dynamic. (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 b04f8198bdc87ec09780b1bb930e305342269dc2..2c00d92c9ba5cca3a86a755a4d4859816cc4be36 100644
--- a/pkg/analyzer/lib/src/generated/constant.dart
+++ b/pkg/analyzer/lib/src/generated/constant.dart
@@ -550,7 +550,7 @@ class ConstantValueComputer {
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)) {
+ if (!_runtimeTypeMatch(dartObject, element.type)) {
errorReporter.reportErrorForNode(
CheckedModeCompileTimeErrorCode.VARIABLE_TYPE_MISMATCH,
declaration, [dartObject.type, element.type]);
@@ -733,7 +733,7 @@ class ConstantValueComputer {
}
}
if (argumentValue != null) {
- if (!argumentValue.isNull && !argumentValue.type.isSubtypeOf(parameter.type)) {
+ if (!_runtimeTypeMatch(argumentValue, parameter.type)) {
errorReporter.reportErrorForNode(
CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH,
errorTarget,
@@ -747,8 +747,7 @@ class ConstantValueComputer {
// 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)) {
+ if (!_runtimeTypeMatch(argumentValue, fieldType)) {
errorReporter.reportErrorForNode(
CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH,
errorTarget,
@@ -778,8 +777,7 @@ class ConstantValueComputer {
PropertyAccessorElement getter = definingClass.getGetter(fieldName);
if (getter != null) {
PropertyInducingElement field = getter.variable;
- if (!evaluationResult.isNull &&
- !evaluationResult.type.isSubtypeOf(field.type)) {
+ if (!_runtimeTypeMatch(evaluationResult, field.type)) {
errorReporter.reportErrorForNode(
CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_FIELD_TYPE_MISMATCH,
node, [evaluationResult.type, fieldName, field.type]);
@@ -876,6 +874,20 @@ class ConstantValueComputer {
}
return constructor;
}
+
+ /**
+ * Check if the object [obj] matches the type [type] according
+ * to runtime type checking rules.
+ */
+ bool _runtimeTypeMatch(DartObjectImpl obj, DartType type) {
+ if (obj.isNull) {
+ return true;
+ }
+ if (type.isUndefined) {
+ return false;
+ }
+ return obj.type.isSubtypeOf(type);
+ }
}
/**
« 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