| 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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 var bound = t.element.bound; | 126 var bound = t.element.bound; |
| 127 if (bound == null) { | 127 if (bound == null) { |
| 128 bound = provider.dynamicType; | 128 bound = provider.dynamicType; |
| 129 } | 129 } |
| 130 return _nonnullableTypes.any((DartType p) => isSubTypeOf(p, bound)); | 130 return _nonnullableTypes.any((DartType p) => isSubTypeOf(p, bound)); |
| 131 } else { | 131 } else { |
| 132 return false; | 132 return false; |
| 133 } | 133 } |
| 134 } | 134 } |
| 135 | 135 |
| 136 bool _anyParameterType(FunctionType ft, bool predicate(DartType t)) { |
| 137 return ft.normalParameterTypes.any(predicate) || |
| 138 ft.optionalParameterTypes.any(predicate) || |
| 139 ft.namedParameterTypes.values.any(predicate); |
| 140 } |
| 141 |
| 136 // TODO(leafp): Revisit this. | 142 // TODO(leafp): Revisit this. |
| 137 bool isGroundType(DartType t) { | 143 bool isGroundType(DartType t) { |
| 138 if (t is FunctionType) return false; | |
| 139 if (t is TypeParameterType) return false; | 144 if (t is TypeParameterType) return false; |
| 140 if (t.isDynamic) return true; | 145 if (t.isDynamic) return true; |
| 141 | 146 |
| 142 // t must be an InterfaceType. | 147 if (t is FunctionType) { |
| 143 var typeArguments = (t as InterfaceType).typeArguments; | 148 if (!t.returnType.isDynamic || |
| 144 for (var typeArgument in typeArguments) { | 149 _anyParameterType(t, (pt) => !pt.isDynamic)) { |
| 145 if (!typeArgument.isDynamic) return false; | 150 return false; |
| 151 } else { |
| 152 return true; |
| 153 } |
| 146 } | 154 } |
| 147 | 155 |
| 148 return true; | 156 if (t is InterfaceType) { |
| 157 var typeArguments = t.typeArguments; |
| 158 for (var typeArgument in typeArguments) { |
| 159 if (!typeArgument.isDynamic) return false; |
| 160 } |
| 161 return true; |
| 162 } |
| 163 |
| 164 throw new StateError("Unexpected type"); |
| 149 } | 165 } |
| 150 | 166 |
| 151 FunctionType getCallMethodType(DartType t) { | 167 FunctionType getCallMethodType(DartType t) { |
| 152 if (t is InterfaceType) { | 168 if (t is InterfaceType) { |
| 153 ClassElement element = t.element; | 169 ClassElement element = t.element; |
| 154 InheritanceManager manager = new InheritanceManager(element.library); | 170 InheritanceManager manager = new InheritanceManager(element.library); |
| 155 FunctionType callType = manager.lookupMemberType(t, "call"); | 171 FunctionType callType = manager.lookupMemberType(t, "call"); |
| 156 return callType; | 172 return callType; |
| 157 } | 173 } |
| 158 return null; | 174 return null; |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 // a dynamic parameter type requires a dynamic call in general. | 519 // a dynamic parameter type requires a dynamic call in general. |
| 504 // However, as an optimization, if we have an original definition, we know | 520 // However, as an optimization, if we have an original definition, we know |
| 505 // dynamic is reified as Object - in this case a regular call is fine. | 521 // dynamic is reified as Object - in this case a regular call is fine. |
| 506 if (call is SimpleIdentifier) { | 522 if (call is SimpleIdentifier) { |
| 507 var element = call.staticElement; | 523 var element = call.staticElement; |
| 508 if (element is FunctionElement || element is MethodElement) { | 524 if (element is FunctionElement || element is MethodElement) { |
| 509 // An original declaration. | 525 // An original declaration. |
| 510 return false; | 526 return false; |
| 511 } | 527 } |
| 512 } | 528 } |
| 529 |
| 513 var ft = t as FunctionType; | 530 var ft = t as FunctionType; |
| 514 for (var parameterType in ft.normalParameterTypes) { | 531 return _anyParameterType(ft, (pt) => pt.isDynamic); |
| 515 if (parameterType.isDynamic) return true; | |
| 516 } | |
| 517 for (var parameterType in ft.optionalParameterTypes) { | |
| 518 if (parameterType.isDynamic) return true; | |
| 519 } | |
| 520 for (var parameterType in ft.namedParameterTypes.values) { | |
| 521 if (parameterType.isDynamic) return true; | |
| 522 } | |
| 523 return false; | |
| 524 } | 532 } |
| 525 } | 533 } |
| OLD | NEW |