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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/task/strong/rules.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 /// Defines static information collected by the type checker and used later by 5 /// Defines static information collected by the type checker and used later by
6 /// emitters to generate code. 6 /// emitters to generate code.
7 // TODO(jmesserly): this was ported from package:dev_compiler, and needs to be 7 // TODO(jmesserly): this was ported from package:dev_compiler, and needs to be
8 // refactored to fit into analyzer. 8 // refactored to fit into analyzer.
9 library analyzer.src.task.strong.info; 9 library analyzer.src.task.strong.info;
10 10
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 // fromT should be an exact type - this will almost certainly fail at 147 // fromT should be an exact type - this will almost certainly fail at
148 // runtime. 148 // runtime.
149 return new UninferredClosure(rules, expression, cast); 149 return new UninferredClosure(rules, expression, cast);
150 } 150 }
151 if (expression is InstanceCreationExpression) { 151 if (expression is InstanceCreationExpression) {
152 // fromT should be an exact type - this will almost certainly fail at 152 // fromT should be an exact type - this will almost certainly fail at
153 // runtime. 153 // runtime.
154 return new StaticTypeError(rules, expression, toT, reason: reason); 154 return new StaticTypeError(rules, expression, toT, reason: reason);
155 } 155 }
156 156
157 // TODO(vsm): Change this to an assert when we have generic methods and
158 // fix TypeRules._coerceTo to disallow implicit sideways casts.
159 if (!rules.isSubTypeOf(toT, fromT)) {
160 assert(toT.isSubtypeOf(fromT) || fromT.isAssignableTo(toT));
161 return new DownCastComposite(rules, expression, cast);
162 }
163
157 // Composite cast: these are more likely to fail. 164 // Composite cast: these are more likely to fail.
158 if (!rules.isGroundType(toT)) { 165 if (!rules.isGroundType(toT)) {
159 // This cast is (probably) due to our different treatment of dynamic. 166 // This cast is (probably) due to our different treatment of dynamic.
160 // It may be more likely to fail at runtime. 167 // It may be more likely to fail at runtime.
161 return new DownCastComposite(rules, expression, cast); 168 if (fromT is InterfaceType) {
169 // For class types, we'd like to allow non-generic down casts, e.g.,
170 // Iterable<T> to List<T>. The intuition here is that raw (generic)
171 // casts are problematic, and we should complain about those.
172 var typeArgs = fromT.typeArguments;
173 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
174 return new DownCastComposite(rules, expression, cast);
175 }
176 } else {
177 return new DownCastComposite(rules, expression, cast);
178 }
162 } 179 }
163 180
164 // Dynamic cast 181 // Dynamic cast
165 if (fromT.isDynamic) { 182 if (fromT.isDynamic) {
166 return new DynamicCast(rules, expression, cast); 183 return new DynamicCast(rules, expression, cast);
167 } 184 }
168 185
169 // Assignment cast 186 // Assignment cast
170 var parent = expression.parent; 187 var parent = expression.parent;
171 if (parent is VariableDeclaration && (parent.initializer == expression)) { 188 if (parent is VariableDeclaration && (parent.initializer == expression)) {
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 /// Better to have `super` at the end, as required by the Dart style guide: 480 /// Better to have `super` at the end, as required by the Dart style guide:
464 /// <http://goo.gl/q1T4BB> 481 /// <http://goo.gl/q1T4BB>
465 /// 482 ///
466 /// For now this is the only pattern we support. 483 /// For now this is the only pattern we support.
467 class InvalidSuperInvocation extends StaticError { 484 class InvalidSuperInvocation extends StaticError {
468 InvalidSuperInvocation(SuperConstructorInvocation node) : super(node); 485 InvalidSuperInvocation(SuperConstructorInvocation node) : super(node);
469 486
470 @override String get message => "super call must be last in an initializer " 487 @override String get message => "super call must be last in an initializer "
471 "list (see http://goo.gl/q1T4BB): {0}"; 488 "list (see http://goo.gl/q1T4BB): {0}";
472 } 489 }
OLDNEW
« 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