| 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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 } | 131 } |
| 132 if (expression is InstanceCreationExpression) { | 132 if (expression is InstanceCreationExpression) { |
| 133 ConstructorElement e = expression.staticElement; | 133 ConstructorElement e = expression.staticElement; |
| 134 if (e == null || !e.isFactory) { | 134 if (e == null || !e.isFactory) { |
| 135 // fromT should be an exact type - this will almost certainly fail at | 135 // fromT should be an exact type - this will almost certainly fail at |
| 136 // runtime. | 136 // runtime. |
| 137 return new StaticTypeError(rules, expression, toT, reason: reason); | 137 return new StaticTypeError(rules, expression, toT, reason: reason); |
| 138 } | 138 } |
| 139 } | 139 } |
| 140 | 140 |
| 141 Element element = null; |
| 142 if (expression is PropertyAccess) { |
| 143 element = expression.propertyName.staticElement; |
| 144 } else if (expression is Identifier) { |
| 145 element = expression.staticElement; |
| 146 } |
| 147 // First class functions and static methods, where we know the original |
| 148 // declaration, will have an exact type, so we know a downcast will fail. |
| 149 if (element is FunctionElement || |
| 150 element is MethodElement && element.isStatic) { |
| 151 return new StaticTypeError(rules, expression, toT, reason: reason); |
| 152 } |
| 153 |
| 141 // TODO(vsm): Change this to an assert when we have generic methods and | 154 // TODO(vsm): Change this to an assert when we have generic methods and |
| 142 // fix TypeRules._coerceTo to disallow implicit sideways casts. | 155 // fix TypeRules._coerceTo to disallow implicit sideways casts. |
| 143 if (!rules.isSubtypeOf(toT, fromT)) { | 156 if (!rules.isSubtypeOf(toT, fromT)) { |
| 144 assert(toT.isSubtypeOf(fromT) || fromT.isAssignableTo(toT)); | 157 assert(toT.isSubtypeOf(fromT) || fromT.isAssignableTo(toT)); |
| 145 return new DownCastComposite(rules, expression, cast); | 158 return new DownCastComposite(rules, expression, cast); |
| 146 } | 159 } |
| 147 | 160 |
| 148 // Composite cast: these are more likely to fail. | 161 // Composite cast: these are more likely to fail. |
| 149 if (!rules.isGroundType(toT)) { | 162 if (!rules.isGroundType(toT)) { |
| 150 // This cast is (probably) due to our different treatment of dynamic. | 163 // This cast is (probably) due to our different treatment of dynamic. |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 @override | 566 @override |
| 554 List<Object> get arguments => [node, baseType, expectedType]; | 567 List<Object> get arguments => [node, baseType, expectedType]; |
| 555 @override | 568 @override |
| 556 String get message => | 569 String get message => |
| 557 'Type check failed: {0} ({1}) is not of type {2}' + | 570 'Type check failed: {0} ({1}) is not of type {2}' + |
| 558 ((reason == null) ? '' : ' because $reason'); | 571 ((reason == null) ? '' : ' because $reason'); |
| 559 | 572 |
| 560 @override | 573 @override |
| 561 String get name => 'STRONG_MODE_STATIC_TYPE_ERROR'; | 574 String get name => 'STRONG_MODE_STATIC_TYPE_ERROR'; |
| 562 } | 575 } |
| OLD | NEW |