| 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 730 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 741 if (classTypeName.typeArguments != null) return false; | 741 if (classTypeName.typeArguments != null) return false; |
| 742 // Infer type arguments | 742 // Infer type arguments |
| 743 var targs = _matchTypes(type, t); | 743 var targs = _matchTypes(type, t); |
| 744 if (targs == null) return false; | 744 if (targs == null) return false; |
| 745 if (e.staticElement == null) return false; | 745 if (e.staticElement == null) return false; |
| 746 var constructorElement = e.staticElement; | 746 var constructorElement = e.staticElement; |
| 747 // From the constructor element get: | 747 // From the constructor element get: |
| 748 // the instantiated type of the constructor, then | 748 // the instantiated type of the constructor, then |
| 749 // the uninstantiated element for the constructor, then | 749 // the uninstantiated element for the constructor, then |
| 750 // the uninstantiated type for the constructor | 750 // the uninstantiated type for the constructor |
| 751 var baseType = constructorElement.type.element.type; | 751 var rawConstructorElement = |
| 752 constructorElement.type.element as ConstructorElement; |
| 753 var baseType = rawConstructorElement.type; |
| 752 if (baseType == null) return false; | 754 if (baseType == null) return false; |
| 753 // From the interface type (instantiated), get: | 755 // From the interface type (instantiated), get: |
| 754 // the uninstantiated element, then | 756 // the uninstantiated element, then |
| 755 // the uninstantiated type, then | 757 // the uninstantiated type, then |
| 756 // the type arguments (aka the type parameters) | 758 // the type arguments (aka the type parameters) |
| 757 var tparams = type.element.type.typeArguments; | 759 var tparams = type.element.type.typeArguments; |
| 758 // Take the uninstantiated constructor type, and replace the type | 760 // Take the uninstantiated constructor type, and replace the type |
| 759 // parameters with the inferred arguments. | 761 // parameters with the inferred arguments. |
| 760 var fType = baseType.substitute2(targs, tparams); | 762 var fType = baseType.substitute2(targs, tparams); |
| 761 { | 763 { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 784 annotateInstanceCreationExpression(e, targs); | 786 annotateInstanceCreationExpression(e, targs); |
| 785 return true; | 787 return true; |
| 786 } | 788 } |
| 787 | 789 |
| 788 bool _inferNamedExpression(NamedExpression e, DartType t, errors) { | 790 bool _inferNamedExpression(NamedExpression e, DartType t, errors) { |
| 789 return _inferExpression(e.expression, t, errors); | 791 return _inferExpression(e.expression, t, errors); |
| 790 } | 792 } |
| 791 | 793 |
| 792 bool _inferFunctionExpression(FunctionExpression e, DartType t, errors) { | 794 bool _inferFunctionExpression(FunctionExpression e, DartType t, errors) { |
| 793 if (t is! FunctionType) return false; | 795 if (t is! FunctionType) return false; |
| 794 var fType = (t as FunctionType); | 796 var fType = t as FunctionType; |
| 795 var eType = e.staticType; | 797 var eType = e.staticType as FunctionType; |
| 796 if (eType is! FunctionType) return false; | 798 if (eType is! FunctionType) return false; |
| 797 | 799 |
| 798 // We have a function literal, so we can treat the arrow type | 800 // We have a function literal, so we can treat the arrow type |
| 799 // as non-fuzzy. Since we're not improving on parameter types | 801 // as non-fuzzy. Since we're not improving on parameter types |
| 800 // currently, if this check fails then we cannot succeed, so | 802 // currently, if this check fails then we cannot succeed, so |
| 801 // bail out. Otherwise, we never need to check the parameter types | 803 // bail out. Otherwise, we never need to check the parameter types |
| 802 // again. | 804 // again. |
| 803 if (!rules.isFunctionSubTypeOf(eType, fType, | 805 if (!rules.isFunctionSubTypeOf(eType, fType, |
| 804 fuzzyArrows: false, ignoreReturn: true)) return false; | 806 fuzzyArrows: false, ignoreReturn: true)) return false; |
| 805 | 807 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 862 var entries = e.entries; | 864 var entries = e.entries; |
| 863 bool inferEntry(MapLiteralEntry entry) { | 865 bool inferEntry(MapLiteralEntry entry) { |
| 864 return _inferExpression(entry.key, kType, errors) && | 866 return _inferExpression(entry.key, kType, errors) && |
| 865 _inferExpression(entry.value, vType, errors); | 867 _inferExpression(entry.value, vType, errors); |
| 866 } | 868 } |
| 867 var b = entries.every(inferEntry); | 869 var b = entries.every(inferEntry); |
| 868 if (b) annotateMapLiteral(e, targs); | 870 if (b) annotateMapLiteral(e, targs); |
| 869 return b; | 871 return b; |
| 870 } | 872 } |
| 871 } | 873 } |
| OLD | NEW |