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 12154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
12165 main() { | 12165 main() { |
12166 dynamic v = 3; | 12166 dynamic v = 3; |
12167 v; // marker | 12167 v; // marker |
12168 }'''; | 12168 }'''; |
12169 _assertPropagatedAssignedType( | 12169 _assertPropagatedAssignedType( |
12170 code, typeProvider.dynamicType, typeProvider.intType); | 12170 code, typeProvider.dynamicType, typeProvider.intType); |
12171 _assertTypeOfMarkedExpression( | 12171 _assertTypeOfMarkedExpression( |
12172 code, typeProvider.dynamicType, typeProvider.intType); | 12172 code, typeProvider.dynamicType, typeProvider.intType); |
12173 } | 12173 } |
12174 | 12174 |
12175 void test_localVariableInference_declaredType_disabled_for_toString() { | |
12176 String name = 'toString'; | |
12177 String code = ''' | |
12178 main() { | |
12179 dynamic $name = () => null; | |
12180 $name(); // marker | |
12181 }'''; | |
12182 SimpleIdentifier identifier = _findMarkedIdentifier(code, "$name = "); | |
12183 expect(identifier.staticType, typeProvider.dynamicType); | |
12184 SimpleIdentifier call = _findMarkedIdentifier(code, "(); // marker"); | |
12185 expect(call.staticType, typeProvider.dynamicType); | |
12186 expect((call.parent as Expression).staticType, typeProvider.dynamicType); | |
12187 } | |
12188 | |
12189 void test_localVariableInference_noInitializer_disabled() { | 12175 void test_localVariableInference_noInitializer_disabled() { |
12190 String code = r''' | 12176 String code = r''' |
12191 main() { | 12177 main() { |
12192 var v; | 12178 var v; |
12193 v = 3; | 12179 v = 3; |
12194 v; // marker | 12180 v; // marker |
12195 }'''; | 12181 }'''; |
12196 _assertPropagatedAssignedType( | 12182 _assertPropagatedAssignedType( |
12197 code, typeProvider.dynamicType, typeProvider.intType); | 12183 code, typeProvider.dynamicType, typeProvider.intType); |
12198 _assertTypeOfMarkedExpression( | 12184 _assertTypeOfMarkedExpression( |
(...skipping 1714 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
13913 _assertTypeOfMarkedExpression( | 13899 _assertTypeOfMarkedExpression( |
13914 r''' | 13900 r''' |
13915 f1(x) { | 13901 f1(x) { |
13916 var v = x.toString(); | 13902 var v = x.toString(); |
13917 return v; // marker | 13903 return v; // marker |
13918 }''', | 13904 }''', |
13919 null, | 13905 null, |
13920 typeProvider.stringType); | 13906 typeProvider.stringType); |
13921 } | 13907 } |
13922 | 13908 |
13909 void test_objectMethodInference_disabled_for_local_function() { | |
Jennifer Messerly
2015/09/28 21:15:47
I noticed these tests seemed to be in the wrong pl
Brian Wilkerson
2015/09/28 21:24:17
That's fine, but just FYI: we always format and so
Jennifer Messerly
2015/09/28 21:39:44
sounds good. I renamed them too (old name was loca
| |
13910 String name = 'toString'; | |
13911 String code = ''' | |
13912 main() { | |
13913 dynamic $name = () => null; | |
13914 $name(); // marker | |
13915 }'''; | |
13916 SimpleIdentifier identifier = _findMarkedIdentifier(code, "$name = "); | |
13917 expect(identifier.staticType, typeProvider.dynamicType); | |
13918 | |
13919 SimpleIdentifier methodName = _findMarkedIdentifier(code, "(); // marker"); | |
13920 MethodInvocation methodInvoke = methodName.parent; | |
13921 expect(methodName.staticType, typeProvider.dynamicType); | |
13922 expect(methodInvoke.staticType, typeProvider.dynamicType); | |
13923 } | |
13924 | |
13925 void test_objectMethodInference_disabled_for_library_prefix() { | |
13926 String name = 'toString'; | |
13927 addNamedSource('/helper.dart', ''' | |
13928 library helper; | |
13929 dynamic $name = (int x) => x + 42'); | |
13930 '''); | |
13931 String code = ''' | |
13932 import 'helper.dart' as helper; | |
13933 main() { | |
13934 helper.$name(); // marker | |
13935 }'''; | |
13936 SimpleIdentifier methodName = _findMarkedIdentifier(code, "(); // marker"); | |
13937 MethodInvocation methodInvoke = methodName.parent; | |
13938 expect(methodName.staticType, null, reason: 'library prefix has no type'); | |
13939 expect(methodInvoke.staticType, typeProvider.dynamicType); | |
13940 } | |
13941 | |
13942 void test_objectMethodInference_enabled_for_cascades() { | |
13943 String name = 'toString'; | |
13944 String code = ''' | |
13945 main() { | |
13946 dynamic obj; | |
13947 obj..$name()..$name(); // marker | |
13948 }'''; | |
13949 SimpleIdentifier methodName = _findMarkedIdentifier(code, "(); // marker"); | |
13950 MethodInvocation methodInvoke = methodName.parent; | |
13951 | |
13952 expect(methodInvoke.staticType, typeProvider.dynamicType); | |
13953 expect(methodInvoke.realTarget.staticType, typeProvider.dynamicType); | |
13954 } | |
13955 | |
13923 void test_propagatedReturnType_localFunction() { | 13956 void test_propagatedReturnType_localFunction() { |
13924 String code = r''' | 13957 String code = r''' |
13925 main() { | 13958 main() { |
13926 f() => 42; | 13959 f() => 42; |
13927 var v = f(); | 13960 var v = f(); |
13928 }'''; | 13961 }'''; |
13929 _assertPropagatedAssignedType( | 13962 _assertPropagatedAssignedType( |
13930 code, typeProvider.dynamicType, typeProvider.intType); | 13963 code, typeProvider.dynamicType, typeProvider.intType); |
13931 } | 13964 } |
13932 | 13965 |
(...skipping 817 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
14750 // check propagated type | 14783 // check propagated type |
14751 FunctionType propagatedType = node.propagatedType as FunctionType; | 14784 FunctionType propagatedType = node.propagatedType as FunctionType; |
14752 expect(propagatedType.returnType, test.typeProvider.stringType); | 14785 expect(propagatedType.returnType, test.typeProvider.stringType); |
14753 } on AnalysisException catch (e, stackTrace) { | 14786 } on AnalysisException catch (e, stackTrace) { |
14754 thrownException[0] = new CaughtException(e, stackTrace); | 14787 thrownException[0] = new CaughtException(e, stackTrace); |
14755 } | 14788 } |
14756 } | 14789 } |
14757 return null; | 14790 return null; |
14758 } | 14791 } |
14759 } | 14792 } |
OLD | NEW |