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

Unified Diff: pkg/analyzer/lib/src/task/strong/info.dart

Issue 1418653003: Fix warnings on implicit casts (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Restore assert Created 5 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/task/strong/rules.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..1aa42b2dfd377339e6124e25a37eabbb7b76f223 100644
--- a/pkg/analyzer/lib/src/task/strong/info.dart
+++ b/pkg/analyzer/lib/src/task/strong/info.dart
@@ -154,11 +154,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)) {
Leaf 2015/10/20 22:30:35 I don't think we know that fromT is generic here d
+ return new DownCastComposite(rules, expression, cast);
+ }
+ } else {
+ return new DownCastComposite(rules, expression, cast);
+ }
}
// Dynamic cast
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/task/strong/rules.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698