| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 runReflectiveTests(TypeProviderImplTest); | 61 runReflectiveTests(TypeProviderImplTest); |
| 62 runReflectiveTests(TypeResolverVisitorTest); | 62 runReflectiveTests(TypeResolverVisitorTest); |
| 63 runReflectiveTests(CheckedModeCompileTimeErrorCodeTest); | 63 runReflectiveTests(CheckedModeCompileTimeErrorCodeTest); |
| 64 runReflectiveTests(ErrorResolverTest); | 64 runReflectiveTests(ErrorResolverTest); |
| 65 runReflectiveTests(HintCodeTest); | 65 runReflectiveTests(HintCodeTest); |
| 66 runReflectiveTests(MemberMapTest); | 66 runReflectiveTests(MemberMapTest); |
| 67 runReflectiveTests(NonHintCodeTest); | 67 runReflectiveTests(NonHintCodeTest); |
| 68 runReflectiveTests(SimpleResolverTest); | 68 runReflectiveTests(SimpleResolverTest); |
| 69 runReflectiveTests(StrictModeTest); | 69 runReflectiveTests(StrictModeTest); |
| 70 runReflectiveTests(TypePropagationTest); | 70 runReflectiveTests(TypePropagationTest); |
| 71 runReflectiveTests(StrongModeTypePropagationTest); |
| 71 } | 72 } |
| 72 | 73 |
| 73 /** | 74 /** |
| 74 * The class `AnalysisContextFactory` defines utility methods used to create ana
lysis contexts | 75 * The class `AnalysisContextFactory` defines utility methods used to create ana
lysis contexts |
| 75 * for testing purposes. | 76 * for testing purposes. |
| 76 */ | 77 */ |
| 77 class AnalysisContextFactory { | 78 class AnalysisContextFactory { |
| 78 static String _DART_MATH = "dart:math"; | 79 static String _DART_MATH = "dart:math"; |
| 79 | 80 |
| 80 static String _DART_INTERCEPTORS = "dart:_interceptors"; | 81 static String _DART_INTERCEPTORS = "dart:_interceptors"; |
| (...skipping 13463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13544 // assertion failure here should be a failure, in both "test_*" and | 13545 // assertion failure here should be a failure, in both "test_*" and |
| 13545 // "fail_*" tests. However, an assertion failure is success for the | 13546 // "fail_*" tests. However, an assertion failure is success for the |
| 13546 // purpose of "fail_*" tests, so without catching them here "fail_*" tests | 13547 // purpose of "fail_*" tests, so without catching them here "fail_*" tests |
| 13547 // can succeed by failing for the wrong reason. | 13548 // can succeed by failing for the wrong reason. |
| 13548 throw new JavaException("Unexexpected assertion failure: $exception"); | 13549 throw new JavaException("Unexexpected assertion failure: $exception"); |
| 13549 } | 13550 } |
| 13550 } | 13551 } |
| 13551 } | 13552 } |
| 13552 | 13553 |
| 13553 @reflectiveTest | 13554 @reflectiveTest |
| 13555 class StrongModeTypePropagationTest extends TypePropagationTest { |
| 13556 void _enterStrongMode() { |
| 13557 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); |
| 13558 options.strongMode = true; |
| 13559 resetWithOptions(options); |
| 13560 } |
| 13561 |
| 13562 void test_localVariableInference_constant() { |
| 13563 _enterStrongMode(); |
| 13564 String code = r''' |
| 13565 main() { |
| 13566 var v = 3; |
| 13567 return v; // marker |
| 13568 }'''; |
| 13569 _assertPropagatedReturnType(code, typeProvider.intType, null); |
| 13570 _assertTypeOfMarkedExpression(code, typeProvider.intType, null); |
| 13571 } |
| 13572 |
| 13573 void test_localVariableInference_transitive_local() { |
| 13574 _enterStrongMode(); |
| 13575 String code = r''' |
| 13576 main() { |
| 13577 var x = 3; |
| 13578 var v = x; |
| 13579 return v; // marker |
| 13580 }'''; |
| 13581 _assertPropagatedReturnType(code, typeProvider.intType, null); |
| 13582 _assertTypeOfMarkedExpression(code, typeProvider.intType, null); |
| 13583 } |
| 13584 |
| 13585 void test_localVariableInference_transitive_toplevel_lexical() { |
| 13586 _enterStrongMode(); |
| 13587 String code = r''' |
| 13588 int x = 3; |
| 13589 main() { |
| 13590 var v = x; |
| 13591 return v; // marker |
| 13592 } |
| 13593 '''; |
| 13594 _assertPropagatedReturnType(code, typeProvider.intType, null); |
| 13595 _assertTypeOfMarkedExpression(code, typeProvider.intType, null); |
| 13596 } |
| 13597 |
| 13598 void test_localVariableInference_transitive_toplevel_reversed() { |
| 13599 _enterStrongMode(); |
| 13600 String code = r''' |
| 13601 main() { |
| 13602 var v = x; |
| 13603 return v; // marker |
| 13604 } |
| 13605 int x = 3; |
| 13606 '''; |
| 13607 _assertPropagatedReturnType(code, typeProvider.intType, null); |
| 13608 _assertTypeOfMarkedExpression(code, typeProvider.intType, null); |
| 13609 } |
| 13610 |
| 13611 void fail_localVariableInference_transitive_toplevel_inferred_lexical() { |
| 13612 _enterStrongMode(); |
| 13613 String code = r''' |
| 13614 final x = 3; |
| 13615 main() { |
| 13616 var v = x; |
| 13617 return v; // marker |
| 13618 } |
| 13619 '''; |
| 13620 _assertPropagatedReturnType(code, typeProvider.intType, null); |
| 13621 _assertTypeOfMarkedExpression(code, typeProvider.intType, null); |
| 13622 } |
| 13623 |
| 13624 void fail_localVariableInference_transitive_toplevel_inferred_reversed() { |
| 13625 _enterStrongMode(); |
| 13626 String code = r''' |
| 13627 main() { |
| 13628 var v = x; |
| 13629 return v; // marker |
| 13630 } |
| 13631 final x = 3; |
| 13632 '''; |
| 13633 _assertPropagatedReturnType(code, typeProvider.intType, null); |
| 13634 _assertTypeOfMarkedExpression(code, typeProvider.intType, null); |
| 13635 } |
| 13636 |
| 13637 void test_localVariableInference_transitive_field_lexical() { |
| 13638 _enterStrongMode(); |
| 13639 String code = r''' |
| 13640 class A { |
| 13641 int x = 3; |
| 13642 f() { |
| 13643 var v = x; |
| 13644 return v; // marker |
| 13645 } |
| 13646 } |
| 13647 main() { |
| 13648 } |
| 13649 '''; |
| 13650 _assertPropagatedReturnType(code, typeProvider.intType, null); |
| 13651 _assertTypeOfMarkedExpression(code, typeProvider.intType, null); |
| 13652 } |
| 13653 |
| 13654 void test_localVariableInference_transitive_field_reversed() { |
| 13655 _enterStrongMode(); |
| 13656 String code = r''' |
| 13657 class A { |
| 13658 f() { |
| 13659 var v = x; |
| 13660 return v; // marker |
| 13661 } |
| 13662 int x = 3; |
| 13663 } |
| 13664 main() { |
| 13665 } |
| 13666 '''; |
| 13667 _assertPropagatedReturnType(code, typeProvider.intType, null); |
| 13668 _assertTypeOfMarkedExpression(code, typeProvider.intType, null); |
| 13669 } |
| 13670 |
| 13671 void fail_localVariableInference_transitive_field_inferred_lexical() { |
| 13672 _enterStrongMode(); |
| 13673 String code = r''' |
| 13674 class A { |
| 13675 final x = 3; |
| 13676 f() { |
| 13677 var v = x; |
| 13678 return v; // marker |
| 13679 } |
| 13680 } |
| 13681 main() { |
| 13682 } |
| 13683 '''; |
| 13684 _assertPropagatedReturnType(code, typeProvider.intType, null); |
| 13685 _assertTypeOfMarkedExpression(code, typeProvider.intType, null); |
| 13686 } |
| 13687 |
| 13688 void fail_localVariableInference_transitive_field_inferred_reversed() { |
| 13689 _enterStrongMode(); |
| 13690 String code = r''' |
| 13691 class A { |
| 13692 f() { |
| 13693 var v = x; |
| 13694 return v; // marker |
| 13695 } |
| 13696 final x = 3; |
| 13697 } |
| 13698 main() { |
| 13699 } |
| 13700 '''; |
| 13701 _assertPropagatedReturnType(code, typeProvider.intType, null); |
| 13702 _assertTypeOfMarkedExpression(code, typeProvider.intType, null); |
| 13703 } |
| 13704 |
| 13705 void test_localVariableInference_declaredType_disabled() { |
| 13706 _enterStrongMode(); |
| 13707 String code = r''' |
| 13708 main() { |
| 13709 dynamic v = 3; |
| 13710 return v; // marker |
| 13711 }'''; |
| 13712 _assertPropagatedReturnType( |
| 13713 code, typeProvider.dynamicType, typeProvider.intType); |
| 13714 _assertTypeOfMarkedExpression( |
| 13715 code, typeProvider.dynamicType, typeProvider.intType); |
| 13716 } |
| 13717 |
| 13718 void test_localVariableInference_bottom_disabled() { |
| 13719 _enterStrongMode(); |
| 13720 String code = r''' |
| 13721 main() { |
| 13722 var v = null; |
| 13723 return v; // marker |
| 13724 }'''; |
| 13725 _assertPropagatedReturnType(code, typeProvider.dynamicType, null); |
| 13726 _assertTypeOfMarkedExpression(code, typeProvider.dynamicType, null); |
| 13727 } |
| 13728 |
| 13729 void test_localVariableInference_noInitializer_disabled() { |
| 13730 _enterStrongMode(); |
| 13731 String code = r''' |
| 13732 main() { |
| 13733 var v; |
| 13734 v = 3; |
| 13735 return v; // marker |
| 13736 }'''; |
| 13737 _assertPropagatedReturnType( |
| 13738 code, typeProvider.dynamicType, typeProvider.intType); |
| 13739 _assertTypeOfMarkedExpression( |
| 13740 code, typeProvider.dynamicType, typeProvider.intType); |
| 13741 } |
| 13742 } |
| 13743 |
| 13744 @reflectiveTest |
| 13554 class TypeProviderImplTest extends EngineTestCase { | 13745 class TypeProviderImplTest extends EngineTestCase { |
| 13555 void test_creation() { | 13746 void test_creation() { |
| 13556 // | 13747 // |
| 13557 // Create a mock library element with the types expected to be in dart:core. | 13748 // Create a mock library element with the types expected to be in dart:core. |
| 13558 // We cannot use either ElementFactory or TestTypeProvider (which uses | 13749 // We cannot use either ElementFactory or TestTypeProvider (which uses |
| 13559 // ElementFactory) because we side-effect the elements in ways that would | 13750 // ElementFactory) because we side-effect the elements in ways that would |
| 13560 // break other tests. | 13751 // break other tests. |
| 13561 // | 13752 // |
| 13562 InterfaceType objectType = _classElement("Object", null).type; | 13753 InterfaceType objectType = _classElement("Object", null).type; |
| 13563 InterfaceType boolType = _classElement("bool", objectType).type; | 13754 InterfaceType boolType = _classElement("bool", objectType).type; |
| (...skipping 763 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14327 // check propagated type | 14518 // check propagated type |
| 14328 FunctionType propagatedType = node.propagatedType as FunctionType; | 14519 FunctionType propagatedType = node.propagatedType as FunctionType; |
| 14329 expect(propagatedType.returnType, test.typeProvider.stringType); | 14520 expect(propagatedType.returnType, test.typeProvider.stringType); |
| 14330 } on AnalysisException catch (e, stackTrace) { | 14521 } on AnalysisException catch (e, stackTrace) { |
| 14331 thrownException[0] = new CaughtException(e, stackTrace); | 14522 thrownException[0] = new CaughtException(e, stackTrace); |
| 14332 } | 14523 } |
| 14333 } | 14524 } |
| 14334 return null; | 14525 return null; |
| 14335 } | 14526 } |
| 14336 } | 14527 } |
| OLD | NEW |