| 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 8036 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8047 return variable; | 8047 return variable; |
| 8048 } | 8048 } |
| 8049 } | 8049 } |
| 8050 } | 8050 } |
| 8051 } | 8051 } |
| 8052 return null; | 8052 return null; |
| 8053 // Not found | 8053 // Not found |
| 8054 } | 8054 } |
| 8055 | 8055 |
| 8056 /** | 8056 /** |
| 8057 * @param code the code that iterates using variable "v". We check that |
| 8058 * "v" has expected static and propagated type. |
| 8059 */ |
| 8060 void _assertPropagatedIterationType(String code, DartType expectedStaticType, |
| 8061 DartType expectedPropagatedType) { |
| 8062 SimpleIdentifier identifier = _findMarkedIdentifier(code, "v in "); |
| 8063 expect(identifier.staticType, same(expectedStaticType)); |
| 8064 expect(identifier.propagatedType, same(expectedPropagatedType)); |
| 8065 } |
| 8066 |
| 8067 /** |
| 8057 * @param code the code that assigns the value to the variable "v", no matter
how. We check that | 8068 * @param code the code that assigns the value to the variable "v", no matter
how. We check that |
| 8058 * "v" has expected static and propagated type. | 8069 * "v" has expected static and propagated type. |
| 8059 */ | 8070 */ |
| 8060 void _assertPropagatedAssignedType(String code, DartType expectedStaticType, | 8071 void _assertPropagatedAssignedType(String code, DartType expectedStaticType, |
| 8061 DartType expectedPropagatedType) { | 8072 DartType expectedPropagatedType) { |
| 8062 SimpleIdentifier identifier = _findMarkedIdentifier(code, "v = "); | 8073 SimpleIdentifier identifier = _findMarkedIdentifier(code, "v = "); |
| 8063 expect(identifier.staticType, same(expectedStaticType)); | 8074 expect(identifier.staticType, same(expectedStaticType)); |
| 8064 expect(identifier.propagatedType, same(expectedPropagatedType)); | 8075 expect(identifier.propagatedType, same(expectedPropagatedType)); |
| 8065 } | 8076 } |
| 8066 | 8077 |
| (...skipping 5664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13731 main() { | 13742 main() { |
| 13732 var v; | 13743 var v; |
| 13733 v = 3; | 13744 v = 3; |
| 13734 return v; // marker | 13745 return v; // marker |
| 13735 }'''; | 13746 }'''; |
| 13736 _assertPropagatedAssignedType( | 13747 _assertPropagatedAssignedType( |
| 13737 code, typeProvider.dynamicType, typeProvider.intType); | 13748 code, typeProvider.dynamicType, typeProvider.intType); |
| 13738 _assertTypeOfMarkedExpression( | 13749 _assertTypeOfMarkedExpression( |
| 13739 code, typeProvider.dynamicType, typeProvider.intType); | 13750 code, typeProvider.dynamicType, typeProvider.intType); |
| 13740 } | 13751 } |
| 13752 |
| 13753 void test_foreachInference_var() { |
| 13754 String code = r''' |
| 13755 main() { |
| 13756 var list = <int>[]; |
| 13757 for (var v in list) { |
| 13758 v; // marker |
| 13759 } |
| 13760 }'''; |
| 13761 _assertPropagatedIterationType(code, typeProvider.intType, null); |
| 13762 _assertTypeOfMarkedExpression(code, typeProvider.intType, null); |
| 13763 } |
| 13764 |
| 13765 void test_foreachInference_var_iterable() { |
| 13766 String code = r''' |
| 13767 main() { |
| 13768 Iterable<int> list = <int>[]; |
| 13769 for (var v in list) { |
| 13770 v; // marker |
| 13771 } |
| 13772 }'''; |
| 13773 _assertPropagatedIterationType(code, typeProvider.intType, null); |
| 13774 _assertTypeOfMarkedExpression(code, typeProvider.intType, null); |
| 13775 } |
| 13776 |
| 13777 void test_foreachInference_var_stream() { |
| 13778 String code = r''' |
| 13779 import 'dart:async'; |
| 13780 main() async { |
| 13781 Stream<int> stream = null; |
| 13782 await for (var v in stream) { |
| 13783 v; // marker |
| 13784 } |
| 13785 }'''; |
| 13786 _assertPropagatedIterationType(code, typeProvider.intType, null); |
| 13787 _assertTypeOfMarkedExpression(code, typeProvider.intType, null); |
| 13788 } |
| 13789 |
| 13790 void test_foreachInference_dynamic_disabled() { |
| 13791 String code = r''' |
| 13792 main() { |
| 13793 var list = <int>[]; |
| 13794 for (dynamic v in list) { |
| 13795 v; // marker |
| 13796 } |
| 13797 }'''; |
| 13798 _assertPropagatedIterationType( |
| 13799 code, typeProvider.dynamicType, typeProvider.intType); |
| 13800 _assertTypeOfMarkedExpression( |
| 13801 code, typeProvider.dynamicType, typeProvider.intType); |
| 13802 } |
| 13803 |
| 13804 void test_foreachInference_reusedVar_disabled() { |
| 13805 String code = r''' |
| 13806 main() { |
| 13807 var list = <int>[]; |
| 13808 var v; |
| 13809 for (v in list) { |
| 13810 v; // marker |
| 13811 } |
| 13812 }'''; |
| 13813 _assertPropagatedIterationType( |
| 13814 code, typeProvider.dynamicType, typeProvider.intType); |
| 13815 _assertTypeOfMarkedExpression( |
| 13816 code, typeProvider.dynamicType, typeProvider.intType); |
| 13817 } |
| 13741 } | 13818 } |
| 13742 | 13819 |
| 13743 @reflectiveTest | 13820 @reflectiveTest |
| 13744 class TypeProviderImplTest extends EngineTestCase { | 13821 class TypeProviderImplTest extends EngineTestCase { |
| 13745 void test_creation() { | 13822 void test_creation() { |
| 13746 // | 13823 // |
| 13747 // Create a mock library element with the types expected to be in dart:core. | 13824 // Create a mock library element with the types expected to be in dart:core. |
| 13748 // We cannot use either ElementFactory or TestTypeProvider (which uses | 13825 // We cannot use either ElementFactory or TestTypeProvider (which uses |
| 13749 // ElementFactory) because we side-effect the elements in ways that would | 13826 // ElementFactory) because we side-effect the elements in ways that would |
| 13750 // break other tests. | 13827 // break other tests. |
| (...skipping 766 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14517 // check propagated type | 14594 // check propagated type |
| 14518 FunctionType propagatedType = node.propagatedType as FunctionType; | 14595 FunctionType propagatedType = node.propagatedType as FunctionType; |
| 14519 expect(propagatedType.returnType, test.typeProvider.stringType); | 14596 expect(propagatedType.returnType, test.typeProvider.stringType); |
| 14520 } on AnalysisException catch (e, stackTrace) { | 14597 } on AnalysisException catch (e, stackTrace) { |
| 14521 thrownException[0] = new CaughtException(e, stackTrace); | 14598 thrownException[0] = new CaughtException(e, stackTrace); |
| 14522 } | 14599 } |
| 14523 } | 14600 } |
| 14524 return null; | 14601 return null; |
| 14525 } | 14602 } |
| 14526 } | 14603 } |
| OLD | NEW |