OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 engine.resolver_test; | 5 library engine.resolver_test; |
6 | 6 |
7 import 'dart:collection'; | 7 import 'dart:collection'; |
8 | 8 |
9 import 'package:analyzer/src/context/context.dart' as newContext; | 9 import 'package:analyzer/src/context/context.dart' as newContext; |
10 import 'package:analyzer/src/generated/ast.dart'; | 10 import 'package:analyzer/src/generated/ast.dart'; |
(...skipping 13425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13436 _assertTypeOfMarkedExpression( | 13436 _assertTypeOfMarkedExpression( |
13437 r''' | 13437 r''' |
13438 f1(x) { | 13438 f1(x) { |
13439 var v = x.toString(); | 13439 var v = x.toString(); |
13440 return v; // marker | 13440 return v; // marker |
13441 }''', | 13441 }''', |
13442 null, | 13442 null, |
13443 typeProvider.stringType); | 13443 typeProvider.stringType); |
13444 } | 13444 } |
13445 | 13445 |
13446 void test_propagatedReturnType_function_hasReturnType_returnsNull() { | |
13447 String code = r''' | |
13448 String f() => null; | |
13449 main() { | |
13450 var v = f(); | |
13451 }'''; | |
13452 _assertPropagatedAssignedType( | |
13453 code, typeProvider.dynamicType, typeProvider.stringType); | |
13454 } | |
13455 | |
13456 void test_propagatedReturnType_function_lessSpecificStaticReturnType() { | |
13457 String code = r''' | |
13458 Object f() => 42; | |
13459 main() { | |
13460 var v = f(); | |
13461 }'''; | |
13462 _assertPropagatedAssignedType( | |
13463 code, typeProvider.dynamicType, typeProvider.intType); | |
13464 } | |
13465 | |
13466 void test_propagatedReturnType_function_moreSpecificStaticReturnType() { | |
13467 String code = r''' | |
13468 int f(v) => (v as num); | |
13469 main() { | |
13470 var v = f(3); | |
13471 }'''; | |
13472 _assertPropagatedAssignedType( | |
13473 code, typeProvider.dynamicType, typeProvider.intType); | |
13474 } | |
13475 | |
13476 void test_propagatedReturnType_function_noReturnTypeName_blockBody_multipleRet
urns() { | |
13477 String code = r''' | |
13478 f() { | |
13479 if (true) return 0; | |
13480 return 1.0; | |
13481 } | |
13482 main() { | |
13483 var v = f(); | |
13484 }'''; | |
13485 _assertPropagatedAssignedType( | |
13486 code, typeProvider.dynamicType, typeProvider.numType); | |
13487 } | |
13488 | |
13489 void test_propagatedReturnType_function_noReturnTypeName_blockBody_oneReturn()
{ | |
13490 String code = r''' | |
13491 f() { | |
13492 var z = 42; | |
13493 return z; | |
13494 } | |
13495 main() { | |
13496 var v = f(); | |
13497 }'''; | |
13498 _assertPropagatedAssignedType( | |
13499 code, typeProvider.dynamicType, typeProvider.intType); | |
13500 } | |
13501 | |
13502 void test_propagatedReturnType_function_noReturnTypeName_expressionBody() { | |
13503 String code = r''' | |
13504 f() => 42; | |
13505 main() { | |
13506 var v = f(); | |
13507 }'''; | |
13508 _assertPropagatedAssignedType( | |
13509 code, typeProvider.dynamicType, typeProvider.intType); | |
13510 } | |
13511 | |
13512 void test_propagatedReturnType_localFunction() { | 13446 void test_propagatedReturnType_localFunction() { |
13513 String code = r''' | 13447 String code = r''' |
13514 main() { | 13448 main() { |
13515 f() => 42; | 13449 f() => 42; |
13516 var v = f(); | 13450 var v = f(); |
13517 }'''; | 13451 }'''; |
13518 _assertPropagatedAssignedType( | 13452 _assertPropagatedAssignedType( |
13519 code, typeProvider.dynamicType, typeProvider.intType); | 13453 code, typeProvider.dynamicType, typeProvider.intType); |
13520 } | 13454 } |
13521 | 13455 |
(...skipping 1072 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14594 // check propagated type | 14528 // check propagated type |
14595 FunctionType propagatedType = node.propagatedType as FunctionType; | 14529 FunctionType propagatedType = node.propagatedType as FunctionType; |
14596 expect(propagatedType.returnType, test.typeProvider.stringType); | 14530 expect(propagatedType.returnType, test.typeProvider.stringType); |
14597 } on AnalysisException catch (e, stackTrace) { | 14531 } on AnalysisException catch (e, stackTrace) { |
14598 thrownException[0] = new CaughtException(e, stackTrace); | 14532 thrownException[0] = new CaughtException(e, stackTrace); |
14599 } | 14533 } |
14600 } | 14534 } |
14601 return null; | 14535 return null; |
14602 } | 14536 } |
14603 } | 14537 } |
OLD | NEW |