| OLD | NEW |
| 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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 // fromT should be an exact type - this will almost certainly fail at | 126 // fromT should be an exact type - this will almost certainly fail at |
| 127 // runtime. | 127 // runtime. |
| 128 return new StaticTypeError(rules, expression, toT, reason: reason); | 128 return new StaticTypeError(rules, expression, toT, reason: reason); |
| 129 } | 129 } |
| 130 if (expression is FunctionExpression) { | 130 if (expression is FunctionExpression) { |
| 131 // fromT should be an exact type - this will almost certainly fail at | 131 // fromT should be an exact type - this will almost certainly fail at |
| 132 // runtime. | 132 // runtime. |
| 133 return new UninferredClosure(rules, expression, cast); | 133 return new UninferredClosure(rules, expression, cast); |
| 134 } | 134 } |
| 135 if (expression is InstanceCreationExpression) { | 135 if (expression is InstanceCreationExpression) { |
| 136 // fromT should be an exact type - this will almost certainly fail at | 136 ConstructorElement e = expression.staticElement; |
| 137 // runtime. | 137 if (e == null || !e.isFactory) { |
| 138 return new StaticTypeError(rules, expression, toT, reason: reason); | 138 // fromT should be an exact type - this will almost certainly fail at |
| 139 // runtime. |
| 140 return new StaticTypeError(rules, expression, toT, reason: reason); |
| 141 } |
| 139 } | 142 } |
| 140 | 143 |
| 141 // TODO(vsm): Change this to an assert when we have generic methods and | 144 // TODO(vsm): Change this to an assert when we have generic methods and |
| 142 // fix TypeRules._coerceTo to disallow implicit sideways casts. | 145 // fix TypeRules._coerceTo to disallow implicit sideways casts. |
| 143 if (!rules.isSubtypeOf(toT, fromT)) { | 146 if (!rules.isSubtypeOf(toT, fromT)) { |
| 144 assert(toT.isSubtypeOf(fromT) || fromT.isAssignableTo(toT)); | 147 assert(toT.isSubtypeOf(fromT) || fromT.isAssignableTo(toT)); |
| 145 return new DownCastComposite(rules, expression, cast); | 148 return new DownCastComposite(rules, expression, cast); |
| 146 } | 149 } |
| 147 | 150 |
| 148 // Composite cast: these are more likely to fail. | 151 // Composite cast: these are more likely to fail. |
| (...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 562 // TODO(vsm,leafp): Remove this. | 565 // TODO(vsm,leafp): Remove this. |
| 563 class UninferredClosure extends DownCast { | 566 class UninferredClosure extends DownCast { |
| 564 UninferredClosure(TypeSystem rules, FunctionExpression expression, Cast cast) | 567 UninferredClosure(TypeSystem rules, FunctionExpression expression, Cast cast) |
| 565 : super._internal(rules, expression, cast); | 568 : super._internal(rules, expression, cast); |
| 566 | 569 |
| 567 @override | 570 @override |
| 568 String get name => 'STRONG_MODE_UNINFERRED_CLOSURE'; | 571 String get name => 'STRONG_MODE_UNINFERRED_CLOSURE'; |
| 569 | 572 |
| 570 toErrorCode() => new StaticTypeWarningCode(name, message); | 573 toErrorCode() => new StaticTypeWarningCode(name, message); |
| 571 } | 574 } |
| OLD | NEW |