| 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 library dev_compiler.src.checker.rules; | 5 library dev_compiler.src.checker.rules; |
| 6 | 6 |
| 7 import 'package:analyzer/src/generated/ast.dart'; | 7 import 'package:analyzer/src/generated/ast.dart'; |
| 8 import 'package:analyzer/src/generated/element.dart'; | 8 import 'package:analyzer/src/generated/element.dart'; |
| 9 import 'package:analyzer/src/generated/resolver.dart'; | 9 import 'package:analyzer/src/generated/resolver.dart'; |
| 10 | 10 |
| (...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 606 // Don't cast top level expressions, only sub-expressions | 606 // Don't cast top level expressions, only sub-expressions |
| 607 return _inferExpression(e, t, errors, cast: false); | 607 return _inferExpression(e, t, errors, cast: false); |
| 608 } | 608 } |
| 609 | 609 |
| 610 /// Downward inference | 610 /// Downward inference |
| 611 bool _inferExpression(Expression e, DartType t, List<String> errors, | 611 bool _inferExpression(Expression e, DartType t, List<String> errors, |
| 612 {cast: true}) { | 612 {cast: true}) { |
| 613 if (e is ConditionalExpression) { | 613 if (e is ConditionalExpression) { |
| 614 return _inferConditionalExpression(e, t, errors); | 614 return _inferConditionalExpression(e, t, errors); |
| 615 } | 615 } |
| 616 if (e is ParenthesizedExpression) { |
| 617 return _inferParenthesizedExpression(e, t, errors); |
| 618 } |
| 616 if (e is Conversion) return _inferExpression(e.node, t, errors); | 619 if (e is Conversion) return _inferExpression(e.node, t, errors); |
| 617 if (rules.isSubTypeOf(rules.getStaticType(e), t)) return true; | 620 if (rules.isSubTypeOf(rules.getStaticType(e), t)) return true; |
| 618 if (cast && rules.getStaticType(e).isDynamic) { | 621 if (cast && rules.getStaticType(e).isDynamic) { |
| 619 annotateCastFromDynamic(e, t); | 622 annotateCastFromDynamic(e, t); |
| 620 return true; | 623 return true; |
| 621 } | 624 } |
| 622 if (e is FunctionExpression) return _inferFunctionExpression(e, t, errors); | 625 if (e is FunctionExpression) return _inferFunctionExpression(e, t, errors); |
| 623 if (e is ListLiteral) return _inferListLiteral(e, t, errors); | 626 if (e is ListLiteral) return _inferListLiteral(e, t, errors); |
| 624 if (e is MapLiteral) return _inferMapLiteral(e, t, errors); | 627 if (e is MapLiteral) return _inferMapLiteral(e, t, errors); |
| 625 if (e is NamedExpression) return _inferNamedExpression(e, t, errors); | 628 if (e is NamedExpression) return _inferNamedExpression(e, t, errors); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 710 } | 713 } |
| 711 | 714 |
| 712 /// These assume that e is not already a subtype of t | 715 /// These assume that e is not already a subtype of t |
| 713 | 716 |
| 714 bool _inferConditionalExpression( | 717 bool _inferConditionalExpression( |
| 715 ConditionalExpression e, DartType t, errors) { | 718 ConditionalExpression e, DartType t, errors) { |
| 716 return _inferExpression(e.thenExpression, t, errors) && | 719 return _inferExpression(e.thenExpression, t, errors) && |
| 717 _inferExpression(e.elseExpression, t, errors); | 720 _inferExpression(e.elseExpression, t, errors); |
| 718 } | 721 } |
| 719 | 722 |
| 723 bool _inferParenthesizedExpression( |
| 724 ParenthesizedExpression e, DartType t, errors) { |
| 725 return _inferExpression(e.expression, t, errors); |
| 726 } |
| 727 |
| 720 bool _inferInstanceCreationExpression( | 728 bool _inferInstanceCreationExpression( |
| 721 InstanceCreationExpression e, DartType t, errors) { | 729 InstanceCreationExpression e, DartType t, errors) { |
| 722 var arguments = e.argumentList.arguments; | 730 var arguments = e.argumentList.arguments; |
| 723 var rawType = rules.getStaticType(e); | 731 var rawType = rules.getStaticType(e); |
| 724 // rawType is the instantiated type of the instance | 732 // rawType is the instantiated type of the instance |
| 725 if (rawType is! InterfaceType) return false; | 733 if (rawType is! InterfaceType) return false; |
| 726 var type = (rawType as InterfaceType); | 734 var type = (rawType as InterfaceType); |
| 727 if (type.typeParameters == null || | 735 if (type.typeParameters == null || |
| 728 type.typeParameters.length == 0) return false; | 736 type.typeParameters.length == 0) return false; |
| 729 if (e.constructorName.type == null) return false; | 737 if (e.constructorName.type == null) return false; |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 854 var entries = e.entries; | 862 var entries = e.entries; |
| 855 bool inferEntry(MapLiteralEntry entry) { | 863 bool inferEntry(MapLiteralEntry entry) { |
| 856 return _inferExpression(entry.key, kType, errors) && | 864 return _inferExpression(entry.key, kType, errors) && |
| 857 _inferExpression(entry.value, vType, errors); | 865 _inferExpression(entry.value, vType, errors); |
| 858 } | 866 } |
| 859 var b = entries.every(inferEntry); | 867 var b = entries.every(inferEntry); |
| 860 if (b) annotateMapLiteral(e, targs); | 868 if (b) annotateMapLiteral(e, targs); |
| 861 return b; | 869 return b; |
| 862 } | 870 } |
| 863 } | 871 } |
| OLD | NEW |