| Index: pkg/analyzer/lib/src/task/strong/info.dart
|
| diff --git a/pkg/analyzer/lib/src/task/strong/info.dart b/pkg/analyzer/lib/src/task/strong/info.dart
|
| index a18f76fe36f45b3b82d84d70e6ed8d7196461b05..f26bb6c871a388aa4ec8e07472f9ed08ea809719 100644
|
| --- a/pkg/analyzer/lib/src/task/strong/info.dart
|
| +++ b/pkg/analyzer/lib/src/task/strong/info.dart
|
| @@ -129,7 +129,6 @@ abstract class DownCast extends CoercionInfo {
|
| // toT <:_R fromT => to <: fromT
|
| // NB: classes with call methods are subtypes of function
|
| // types, but the function type is not assignable to the class
|
| - assert(toT.isSubtypeOf(fromT) || fromT.isAssignableTo(toT));
|
|
|
| // Handle null call specially.
|
| if (expression is NullLiteral) {
|
| @@ -154,11 +153,28 @@ abstract class DownCast extends CoercionInfo {
|
| return new StaticTypeError(rules, expression, toT, reason: reason);
|
| }
|
|
|
| + // TODO(vsm): Change this to an assert when we have generic methods and
|
| + // fix TypeRules._coerceTo to disallow implicit sideways casts.
|
| + if (!rules.isSubTypeOf(toT, fromT)) {
|
| + assert(toT.isSubtypeOf(fromT) || fromT.isAssignableTo(toT));
|
| + return new DownCastComposite(rules, expression, cast);
|
| + }
|
| +
|
| // Composite cast: these are more likely to fail.
|
| if (!rules.isGroundType(toT)) {
|
| // This cast is (probably) due to our different treatment of dynamic.
|
| // It may be more likely to fail at runtime.
|
| - return new DownCastComposite(rules, expression, cast);
|
| + if (fromT is InterfaceType) {
|
| + // For class types, we'd like to allow non-generic down casts, e.g.,
|
| + // Iterable<T> to List<T>. The intuition here is that raw (generic)
|
| + // casts are problematic, and we should complain about those.
|
| + var typeArgs = fromT.typeArguments;
|
| + if (typeArgs.isEmpty || typeArgs.any((t) => t.isDynamic)) {
|
| + return new DownCastComposite(rules, expression, cast);
|
| + }
|
| + } else {
|
| + return new DownCastComposite(rules, expression, cast);
|
| + }
|
| }
|
|
|
| // Dynamic cast
|
|
|