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 12691 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12702 } | 12702 } |
12703 | 12703 |
12704 void test_getType_noScope() { | 12704 void test_getType_noScope() { |
12705 TypeOverrideManager manager = new TypeOverrideManager(); | 12705 TypeOverrideManager manager = new TypeOverrideManager(); |
12706 expect(manager.getType(ElementFactory.localVariableElement2("v")), isNull); | 12706 expect(manager.getType(ElementFactory.localVariableElement2("v")), isNull); |
12707 } | 12707 } |
12708 } | 12708 } |
12709 | 12709 |
12710 @reflectiveTest | 12710 @reflectiveTest |
12711 class TypePropagationTest extends ResolverTestCase { | 12711 class TypePropagationTest extends ResolverTestCase { |
| 12712 void fail_finalPropertyInducingVariable_classMember_instance() { |
| 12713 addNamedSource( |
| 12714 "/lib.dart", |
| 12715 r''' |
| 12716 class A { |
| 12717 final v = 0; |
| 12718 }'''); |
| 12719 String code = r''' |
| 12720 import 'lib.dart'; |
| 12721 f(A a) { |
| 12722 return a.v; // marker |
| 12723 }'''; |
| 12724 _assertTypeOfMarkedExpression( |
| 12725 code, typeProvider.dynamicType, typeProvider.intType); |
| 12726 } |
| 12727 |
| 12728 void fail_finalPropertyInducingVariable_classMember_instance_inherited() { |
| 12729 addNamedSource( |
| 12730 "/lib.dart", |
| 12731 r''' |
| 12732 class A { |
| 12733 final v = 0; |
| 12734 }'''); |
| 12735 String code = r''' |
| 12736 import 'lib.dart'; |
| 12737 class B extends A { |
| 12738 m() { |
| 12739 return v; // marker |
| 12740 } |
| 12741 }'''; |
| 12742 _assertTypeOfMarkedExpression( |
| 12743 code, typeProvider.dynamicType, typeProvider.intType); |
| 12744 } |
| 12745 |
| 12746 void fail_finalPropertyInducingVariable_classMember_instance_propagatedTarget(
) { |
| 12747 addNamedSource( |
| 12748 "/lib.dart", |
| 12749 r''' |
| 12750 class A { |
| 12751 final v = 0; |
| 12752 }'''); |
| 12753 String code = r''' |
| 12754 import 'lib.dart'; |
| 12755 f(p) { |
| 12756 if (p is A) { |
| 12757 return p.v; // marker |
| 12758 } |
| 12759 }'''; |
| 12760 _assertTypeOfMarkedExpression( |
| 12761 code, typeProvider.dynamicType, typeProvider.intType); |
| 12762 } |
| 12763 |
| 12764 void fail_finalPropertyInducingVariable_classMember_instance_unprefixed() { |
| 12765 String code = r''' |
| 12766 class A { |
| 12767 final v = 0; |
| 12768 m() { |
| 12769 v; // marker |
| 12770 } |
| 12771 }'''; |
| 12772 _assertTypeOfMarkedExpression( |
| 12773 code, typeProvider.dynamicType, typeProvider.intType); |
| 12774 } |
| 12775 |
12712 void fail_finalPropertyInducingVariable_classMember_static() { | 12776 void fail_finalPropertyInducingVariable_classMember_static() { |
12713 addNamedSource( | 12777 addNamedSource( |
12714 "/lib.dart", | 12778 "/lib.dart", |
12715 r''' | 12779 r''' |
12716 class A { | 12780 class A { |
12717 static final V = 0; | 12781 static final V = 0; |
12718 }'''); | 12782 }'''); |
12719 String code = r''' | 12783 String code = r''' |
12720 import 'lib.dart'; | 12784 import 'lib.dart'; |
12721 f() { | 12785 f() { |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13024 Source source = addSource(code); | 13088 Source source = addSource(code); |
13025 LibraryElement library = resolve2(source); | 13089 LibraryElement library = resolve2(source); |
13026 assertNoErrors(source); | 13090 assertNoErrors(source); |
13027 verify([source]); | 13091 verify([source]); |
13028 CompilationUnit unit = resolveCompilationUnit(source, library); | 13092 CompilationUnit unit = resolveCompilationUnit(source, library); |
13029 SimpleIdentifier identifier = EngineTestCase.findNode( | 13093 SimpleIdentifier identifier = EngineTestCase.findNode( |
13030 unit, code, "context", (node) => node is SimpleIdentifier); | 13094 unit, code, "context", (node) => node is SimpleIdentifier); |
13031 expect(identifier.propagatedType.name, "CanvasRenderingContext2D"); | 13095 expect(identifier.propagatedType.name, "CanvasRenderingContext2D"); |
13032 } | 13096 } |
13033 | 13097 |
13034 void test_finalPropertyInducingVariable_classMember_instance() { | |
13035 addNamedSource( | |
13036 "/lib.dart", | |
13037 r''' | |
13038 class A { | |
13039 final v = 0; | |
13040 }'''); | |
13041 String code = r''' | |
13042 import 'lib.dart'; | |
13043 f(A a) { | |
13044 return a.v; // marker | |
13045 }'''; | |
13046 _assertTypeOfMarkedExpression( | |
13047 code, typeProvider.dynamicType, typeProvider.intType); | |
13048 } | |
13049 | |
13050 void test_finalPropertyInducingVariable_classMember_instance_inherited() { | |
13051 addNamedSource( | |
13052 "/lib.dart", | |
13053 r''' | |
13054 class A { | |
13055 final v = 0; | |
13056 }'''); | |
13057 String code = r''' | |
13058 import 'lib.dart'; | |
13059 class B extends A { | |
13060 m() { | |
13061 return v; // marker | |
13062 } | |
13063 }'''; | |
13064 _assertTypeOfMarkedExpression( | |
13065 code, typeProvider.dynamicType, typeProvider.intType); | |
13066 } | |
13067 | |
13068 void test_finalPropertyInducingVariable_classMember_instance_propagatedTarget(
) { | |
13069 addNamedSource( | |
13070 "/lib.dart", | |
13071 r''' | |
13072 class A { | |
13073 final v = 0; | |
13074 }'''); | |
13075 String code = r''' | |
13076 import 'lib.dart'; | |
13077 f(p) { | |
13078 if (p is A) { | |
13079 return p.v; // marker | |
13080 } | |
13081 }'''; | |
13082 _assertTypeOfMarkedExpression( | |
13083 code, typeProvider.dynamicType, typeProvider.intType); | |
13084 } | |
13085 | |
13086 void test_finalPropertyInducingVariable_classMember_instance_unprefixed() { | |
13087 String code = r''' | |
13088 class A { | |
13089 final v = 0; | |
13090 m() { | |
13091 v; // marker | |
13092 } | |
13093 }'''; | |
13094 _assertTypeOfMarkedExpression( | |
13095 code, typeProvider.dynamicType, typeProvider.intType); | |
13096 } | |
13097 | |
13098 void test_forEach() { | 13098 void test_forEach() { |
13099 String code = r''' | 13099 String code = r''' |
13100 main() { | 13100 main() { |
13101 var list = <String> []; | 13101 var list = <String> []; |
13102 for (var e in list) { | 13102 for (var e in list) { |
13103 e; | 13103 e; |
13104 } | 13104 } |
13105 }'''; | 13105 }'''; |
13106 Source source = addSource(code); | 13106 Source source = addSource(code); |
13107 LibraryElement library = resolve2(source); | 13107 LibraryElement library = resolve2(source); |
(...skipping 1993 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15101 | 15101 |
15102 void _resolveTestUnit(String code) { | 15102 void _resolveTestUnit(String code) { |
15103 testCode = code; | 15103 testCode = code; |
15104 testSource = addSource(testCode); | 15104 testSource = addSource(testCode); |
15105 LibraryElement library = resolve2(testSource); | 15105 LibraryElement library = resolve2(testSource); |
15106 assertNoErrors(testSource); | 15106 assertNoErrors(testSource); |
15107 verify([testSource]); | 15107 verify([testSource]); |
15108 testUnit = resolveCompilationUnit(testSource, library); | 15108 testUnit = resolveCompilationUnit(testSource, library); |
15109 } | 15109 } |
15110 } | 15110 } |
OLD | NEW |