| 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 // TODO(jmesserly): this was ported from package:dev_compiler, and needs to be | 5 // TODO(jmesserly): this was ported from package:dev_compiler, and needs to be |
| 6 // refactored to fit into analyzer. | 6 // refactored to fit into analyzer. |
| 7 library analyzer.src.task.strong.rules; | 7 library analyzer.src.task.strong.rules; |
| 8 | 8 |
| 9 import 'package:analyzer/src/generated/ast.dart'; | 9 import 'package:analyzer/src/generated/ast.dart'; |
| 10 import 'package:analyzer/src/generated/element.dart'; | 10 import 'package:analyzer/src/generated/element.dart'; |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 if (t1 is TypeParameterType) { | 314 if (t1 is TypeParameterType) { |
| 315 DartType bound = t1.element.bound; | 315 DartType bound = t1.element.bound; |
| 316 if (bound == null) return false; | 316 if (bound == null) return false; |
| 317 return isSubTypeOf(bound, t2); | 317 return isSubTypeOf(bound, t2); |
| 318 } | 318 } |
| 319 | 319 |
| 320 if (t2 is TypeParameterType) { | 320 if (t2 is TypeParameterType) { |
| 321 return false; | 321 return false; |
| 322 } | 322 } |
| 323 | 323 |
| 324 if (t1.isVoid || t2.isVoid) { |
| 325 return false; |
| 326 } |
| 327 |
| 324 if (t2.isDartCoreFunction) { | 328 if (t2.isDartCoreFunction) { |
| 325 if (t1 is FunctionType) return true; | 329 if (t1 is FunctionType) return true; |
| 326 if (t1.element is ClassElement) { | 330 if (t1.element is ClassElement) { |
| 327 if ((t1.element as ClassElement).getMethod("call") != null) return true; | 331 if ((t1.element as ClassElement).getMethod("call") != null) return true; |
| 328 } | 332 } |
| 329 } | 333 } |
| 330 | 334 |
| 331 // "Traditional" name-based subtype check. | 335 // "Traditional" name-based subtype check. |
| 332 if (t1 is InterfaceType && t2 is InterfaceType) { | 336 if (t1 is InterfaceType && t2 is InterfaceType) { |
| 333 return _isInterfaceSubTypeOf(t1, t2); | 337 return _isInterfaceSubTypeOf(t1, t2); |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 511 {cast: true}) { | 515 {cast: true}) { |
| 512 if (rules.isSubTypeOf(rules.getStaticType(e), t)) return true; | 516 if (rules.isSubTypeOf(rules.getStaticType(e), t)) return true; |
| 513 if (cast && rules.getStaticType(e).isDynamic) { | 517 if (cast && rules.getStaticType(e).isDynamic) { |
| 514 annotateCastFromDynamic(e, t); | 518 annotateCastFromDynamic(e, t); |
| 515 return true; | 519 return true; |
| 516 } | 520 } |
| 517 errors.add("$e cannot be typed as $t"); | 521 errors.add("$e cannot be typed as $t"); |
| 518 return false; | 522 return false; |
| 519 } | 523 } |
| 520 } | 524 } |
| OLD | NEW |