| 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 12569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12580 return (stmt as ReturnStatement).expression; | 12580 return (stmt as ReturnStatement).expression; |
| 12581 } | 12581 } |
| 12582 } | 12582 } |
| 12583 expect(functionReturnValue(0).staticType, typeProvider.intType); | 12583 expect(functionReturnValue(0).staticType, typeProvider.intType); |
| 12584 expect(functionReturnValue(1).staticType, typeProvider.intType); | 12584 expect(functionReturnValue(1).staticType, typeProvider.intType); |
| 12585 expect(functionReturnValue(2).staticType, typeProvider.intType); | 12585 expect(functionReturnValue(2).staticType, typeProvider.intType); |
| 12586 expect(functionReturnValue(3).staticType, typeProvider.dynamicType); | 12586 expect(functionReturnValue(3).staticType, typeProvider.dynamicType); |
| 12587 expect(functionReturnValue(4).staticType, typeProvider.stringType); | 12587 expect(functionReturnValue(4).staticType, typeProvider.stringType); |
| 12588 } | 12588 } |
| 12589 | 12589 |
| 12590 void test_inference_hints() { |
| 12591 Source source = addSource(r''' |
| 12592 void main () { |
| 12593 var x = 3; |
| 12594 List<int> l0 = []; |
| 12595 } |
| 12596 '''); |
| 12597 LibraryElement library = resolve2(source); |
| 12598 assertNoErrors(source); |
| 12599 verify([source]); |
| 12600 } |
| 12601 |
| 12590 void test_instanceCreation() { | 12602 void test_instanceCreation() { |
| 12591 String code = r''' | 12603 String code = r''' |
| 12592 class A<S, T> { | 12604 class A<S, T> { |
| 12593 S x; | 12605 S x; |
| 12594 T y; | 12606 T y; |
| 12595 A(this.x, this.y); | 12607 A(this.x, this.y); |
| 12596 A.named(this.x, this.y); | 12608 A.named(this.x, this.y); |
| 12597 } | 12609 } |
| 12598 | 12610 |
| 12599 class B<S, T> extends A<T, S> { | 12611 class B<S, T> extends A<T, S> { |
| (...skipping 1212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13812 } | 13824 } |
| 13813 | 13825 |
| 13814 void test_getType_noScope() { | 13826 void test_getType_noScope() { |
| 13815 TypeOverrideManager manager = new TypeOverrideManager(); | 13827 TypeOverrideManager manager = new TypeOverrideManager(); |
| 13816 expect(manager.getType(ElementFactory.localVariableElement2("v")), isNull); | 13828 expect(manager.getType(ElementFactory.localVariableElement2("v")), isNull); |
| 13817 } | 13829 } |
| 13818 } | 13830 } |
| 13819 | 13831 |
| 13820 @reflectiveTest | 13832 @reflectiveTest |
| 13821 class TypePropagationTest extends ResolverTestCase { | 13833 class TypePropagationTest extends ResolverTestCase { |
| 13822 void test_invocation_target_prefixed() { | |
| 13823 addNamedSource( | |
| 13824 '/helper.dart', | |
| 13825 ''' | |
| 13826 library helper; | |
| 13827 int max(int x, int y) => 0; | |
| 13828 '''); | |
| 13829 String code = ''' | |
| 13830 import 'helper.dart' as helper; | |
| 13831 main() { | |
| 13832 helper.max(10, 10); // marker | |
| 13833 }'''; | |
| 13834 SimpleIdentifier methodName = | |
| 13835 _findMarkedIdentifier(code, "(10, 10); // marker"); | |
| 13836 MethodInvocation methodInvoke = methodName.parent; | |
| 13837 expect(methodInvoke.methodName.staticElement, isNotNull); | |
| 13838 expect(methodInvoke.methodName.propagatedElement, isNull); | |
| 13839 } | |
| 13840 | |
| 13841 void fail_mergePropagatedTypesAtJoinPoint_1() { | 13834 void fail_mergePropagatedTypesAtJoinPoint_1() { |
| 13842 // https://code.google.com/p/dart/issues/detail?id=19929 | 13835 // https://code.google.com/p/dart/issues/detail?id=19929 |
| 13843 _assertTypeOfMarkedExpression( | 13836 _assertTypeOfMarkedExpression( |
| 13844 r''' | 13837 r''' |
| 13845 f1(x) { | 13838 f1(x) { |
| 13846 var y = []; | 13839 var y = []; |
| 13847 if (x) { | 13840 if (x) { |
| 13848 y = 0; | 13841 y = 0; |
| 13849 } else { | 13842 } else { |
| 13850 y = ''; | 13843 y = ''; |
| (...skipping 799 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14650 expect(identifier.propagatedType, same(null)); | 14643 expect(identifier.propagatedType, same(null)); |
| 14651 } | 14644 } |
| 14652 { | 14645 { |
| 14653 SimpleIdentifier identifier = EngineTestCase.findNode( | 14646 SimpleIdentifier identifier = EngineTestCase.findNode( |
| 14654 unit, code, "v; // marker", (node) => node is SimpleIdentifier); | 14647 unit, code, "v; // marker", (node) => node is SimpleIdentifier); |
| 14655 expect(identifier.staticType, same(typeProvider.intType)); | 14648 expect(identifier.staticType, same(typeProvider.intType)); |
| 14656 expect(identifier.propagatedType, same(null)); | 14649 expect(identifier.propagatedType, same(null)); |
| 14657 } | 14650 } |
| 14658 } | 14651 } |
| 14659 | 14652 |
| 14653 void test_invocation_target_prefixed() { |
| 14654 addNamedSource( |
| 14655 '/helper.dart', |
| 14656 ''' |
| 14657 library helper; |
| 14658 int max(int x, int y) => 0; |
| 14659 '''); |
| 14660 String code = ''' |
| 14661 import 'helper.dart' as helper; |
| 14662 main() { |
| 14663 helper.max(10, 10); // marker |
| 14664 }'''; |
| 14665 SimpleIdentifier methodName = |
| 14666 _findMarkedIdentifier(code, "(10, 10); // marker"); |
| 14667 MethodInvocation methodInvoke = methodName.parent; |
| 14668 expect(methodInvoke.methodName.staticElement, isNotNull); |
| 14669 expect(methodInvoke.methodName.propagatedElement, isNull); |
| 14670 } |
| 14671 |
| 14660 void test_is_conditional() { | 14672 void test_is_conditional() { |
| 14661 Source source = addSource(r''' | 14673 Source source = addSource(r''' |
| 14662 class A {} | 14674 class A {} |
| 14663 A f(var p) { | 14675 A f(var p) { |
| 14664 return (p is A) ? p : null; | 14676 return (p is A) ? p : null; |
| 14665 }'''); | 14677 }'''); |
| 14666 LibraryElement library = resolve2(source); | 14678 LibraryElement library = resolve2(source); |
| 14667 assertNoErrors(source); | 14679 assertNoErrors(source); |
| 14668 verify([source]); | 14680 verify([source]); |
| 14669 CompilationUnit unit = resolveCompilationUnit(source, library); | 14681 CompilationUnit unit = resolveCompilationUnit(source, library); |
| (...skipping 1574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 16244 | 16256 |
| 16245 void _resolveTestUnit(String code) { | 16257 void _resolveTestUnit(String code) { |
| 16246 testCode = code; | 16258 testCode = code; |
| 16247 testSource = addSource(testCode); | 16259 testSource = addSource(testCode); |
| 16248 LibraryElement library = resolve2(testSource); | 16260 LibraryElement library = resolve2(testSource); |
| 16249 assertNoErrors(testSource); | 16261 assertNoErrors(testSource); |
| 16250 verify([testSource]); | 16262 verify([testSource]); |
| 16251 testUnit = resolveCompilationUnit(testSource, library); | 16263 testUnit = resolveCompilationUnit(testSource, library); |
| 16252 } | 16264 } |
| 16253 } | 16265 } |
| OLD | NEW |