Chromium Code Reviews| 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( | |
| 13762 code, typeProvider.intType, typeProvider.intType); | |
|
Brian Wilkerson
2015/08/28 20:59:33
I might be misreading the test, but it looks like
Leaf
2015/09/01 21:21:02
I changed visitForEachStatementInScope as discusse
| |
| 13763 _assertTypeOfMarkedExpression(code, typeProvider.intType, null); | |
| 13764 } | |
| 13765 | |
| 13766 void test_foreachInference_dynamic_disabled() { | |
| 13767 String code = r''' | |
| 13768 main() { | |
| 13769 var list = <int>[]; | |
| 13770 for (dynamic v in list) { | |
| 13771 v; // marker | |
| 13772 } | |
| 13773 }'''; | |
| 13774 _assertPropagatedIterationType( | |
| 13775 code, typeProvider.dynamicType, typeProvider.intType); | |
| 13776 _assertTypeOfMarkedExpression( | |
| 13777 code, typeProvider.dynamicType, typeProvider.intType); | |
| 13778 } | |
| 13779 | |
| 13780 void test_foreachInference_reusedVar_disabled() { | |
| 13781 String code = r''' | |
| 13782 main() { | |
| 13783 var list = <int>[]; | |
| 13784 var v; | |
| 13785 for (v in list) { | |
| 13786 v; // marker | |
| 13787 } | |
| 13788 }'''; | |
| 13789 _assertPropagatedIterationType( | |
| 13790 code, typeProvider.dynamicType, typeProvider.intType); | |
| 13791 _assertTypeOfMarkedExpression( | |
| 13792 code, typeProvider.dynamicType, typeProvider.intType); | |
| 13793 } | |
| 13794 | |
| 13795 void fail_foreachInference_var_map() { | |
| 13796 String code = r''' | |
| 13797 main() { | |
| 13798 Map<int, String> map = <int, String>{}; | |
| 13799 for (var v in map) { | |
| 13800 v; // marker | |
| 13801 } | |
| 13802 }'''; | |
| 13803 _assertPropagatedIterationType(code, typeProvider.intType, null); | |
| 13804 _assertTypeOfMarkedExpression(code, typeProvider.intType, null); | |
| 13805 } | |
| 13741 } | 13806 } |
| 13742 | 13807 |
| 13743 @reflectiveTest | 13808 @reflectiveTest |
| 13744 class TypeProviderImplTest extends EngineTestCase { | 13809 class TypeProviderImplTest extends EngineTestCase { |
| 13745 void test_creation() { | 13810 void test_creation() { |
| 13746 // | 13811 // |
| 13747 // Create a mock library element with the types expected to be in dart:core. | 13812 // Create a mock library element with the types expected to be in dart:core. |
| 13748 // We cannot use either ElementFactory or TestTypeProvider (which uses | 13813 // We cannot use either ElementFactory or TestTypeProvider (which uses |
| 13749 // ElementFactory) because we side-effect the elements in ways that would | 13814 // ElementFactory) because we side-effect the elements in ways that would |
| 13750 // break other tests. | 13815 // break other tests. |
| (...skipping 766 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 14517 // check propagated type | 14582 // check propagated type |
| 14518 FunctionType propagatedType = node.propagatedType as FunctionType; | 14583 FunctionType propagatedType = node.propagatedType as FunctionType; |
| 14519 expect(propagatedType.returnType, test.typeProvider.stringType); | 14584 expect(propagatedType.returnType, test.typeProvider.stringType); |
| 14520 } on AnalysisException catch (e, stackTrace) { | 14585 } on AnalysisException catch (e, stackTrace) { |
| 14521 thrownException[0] = new CaughtException(e, stackTrace); | 14586 thrownException[0] = new CaughtException(e, stackTrace); |
| 14522 } | 14587 } |
| 14523 } | 14588 } |
| 14524 return null; | 14589 return null; |
| 14525 } | 14590 } |
| 14526 } | 14591 } |
| OLD | NEW |