| 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 12783 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12794 } | 12794 } |
| 12795 | 12795 |
| 12796 void test_getType_noScope() { | 12796 void test_getType_noScope() { |
| 12797 TypeOverrideManager manager = new TypeOverrideManager(); | 12797 TypeOverrideManager manager = new TypeOverrideManager(); |
| 12798 expect(manager.getType(ElementFactory.localVariableElement2("v")), isNull); | 12798 expect(manager.getType(ElementFactory.localVariableElement2("v")), isNull); |
| 12799 } | 12799 } |
| 12800 } | 12800 } |
| 12801 | 12801 |
| 12802 @reflectiveTest | 12802 @reflectiveTest |
| 12803 class TypePropagationTest extends ResolverTestCase { | 12803 class TypePropagationTest extends ResolverTestCase { |
| 12804 void fail_finalPropertyInducingVariable_classMember_instance() { | |
| 12805 addNamedSource( | |
| 12806 "/lib.dart", | |
| 12807 r''' | |
| 12808 class A { | |
| 12809 final v = 0; | |
| 12810 }'''); | |
| 12811 String code = r''' | |
| 12812 import 'lib.dart'; | |
| 12813 f(A a) { | |
| 12814 return a.v; // marker | |
| 12815 }'''; | |
| 12816 _assertTypeOfMarkedExpression( | |
| 12817 code, typeProvider.dynamicType, typeProvider.intType); | |
| 12818 } | |
| 12819 | |
| 12820 void fail_finalPropertyInducingVariable_classMember_instance_inherited() { | |
| 12821 addNamedSource( | |
| 12822 "/lib.dart", | |
| 12823 r''' | |
| 12824 class A { | |
| 12825 final v = 0; | |
| 12826 }'''); | |
| 12827 String code = r''' | |
| 12828 import 'lib.dart'; | |
| 12829 class B extends A { | |
| 12830 m() { | |
| 12831 return v; // marker | |
| 12832 } | |
| 12833 }'''; | |
| 12834 _assertTypeOfMarkedExpression( | |
| 12835 code, typeProvider.dynamicType, typeProvider.intType); | |
| 12836 } | |
| 12837 | |
| 12838 void fail_finalPropertyInducingVariable_classMember_instance_propagatedTarget(
) { | |
| 12839 addNamedSource( | |
| 12840 "/lib.dart", | |
| 12841 r''' | |
| 12842 class A { | |
| 12843 final v = 0; | |
| 12844 }'''); | |
| 12845 String code = r''' | |
| 12846 import 'lib.dart'; | |
| 12847 f(p) { | |
| 12848 if (p is A) { | |
| 12849 return p.v; // marker | |
| 12850 } | |
| 12851 }'''; | |
| 12852 _assertTypeOfMarkedExpression( | |
| 12853 code, typeProvider.dynamicType, typeProvider.intType); | |
| 12854 } | |
| 12855 | |
| 12856 void fail_finalPropertyInducingVariable_classMember_static() { | |
| 12857 addNamedSource( | |
| 12858 "/lib.dart", | |
| 12859 r''' | |
| 12860 class A { | |
| 12861 static final V = 0; | |
| 12862 }'''); | |
| 12863 String code = r''' | |
| 12864 import 'lib.dart'; | |
| 12865 f() { | |
| 12866 return A.V; // marker | |
| 12867 }'''; | |
| 12868 _assertTypeOfMarkedExpression( | |
| 12869 code, typeProvider.dynamicType, typeProvider.intType); | |
| 12870 } | |
| 12871 | |
| 12872 void fail_finalPropertyInducingVariable_topLevelVaraible_prefixed() { | |
| 12873 addNamedSource("/lib.dart", "final V = 0;"); | |
| 12874 String code = r''' | |
| 12875 import 'lib.dart' as p; | |
| 12876 f() { | |
| 12877 var v2 = p.V; // marker prefixed | |
| 12878 }'''; | |
| 12879 _assertTypeOfMarkedExpression( | |
| 12880 code, typeProvider.dynamicType, typeProvider.intType); | |
| 12881 } | |
| 12882 | |
| 12883 void fail_finalPropertyInducingVariable_topLevelVaraible_simple() { | |
| 12884 addNamedSource("/lib.dart", "final V = 0;"); | |
| 12885 String code = r''' | |
| 12886 import 'lib.dart'; | |
| 12887 f() { | |
| 12888 return V; // marker simple | |
| 12889 }'''; | |
| 12890 _assertTypeOfMarkedExpression( | |
| 12891 code, typeProvider.dynamicType, typeProvider.intType); | |
| 12892 } | |
| 12893 | |
| 12894 void fail_mergePropagatedTypesAtJoinPoint_1() { | 12804 void fail_mergePropagatedTypesAtJoinPoint_1() { |
| 12895 // https://code.google.com/p/dart/issues/detail?id=19929 | 12805 // https://code.google.com/p/dart/issues/detail?id=19929 |
| 12896 _assertTypeOfMarkedExpression( | 12806 _assertTypeOfMarkedExpression( |
| 12897 r''' | 12807 r''' |
| 12898 f1(x) { | 12808 f1(x) { |
| 12899 var y = []; | 12809 var y = []; |
| 12900 if (x) { | 12810 if (x) { |
| 12901 y = 0; | 12811 y = 0; |
| 12902 } else { | 12812 } else { |
| 12903 y = ''; | 12813 y = ''; |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13168 Source source = addSource(code); | 13078 Source source = addSource(code); |
| 13169 LibraryElement library = resolve2(source); | 13079 LibraryElement library = resolve2(source); |
| 13170 assertNoErrors(source); | 13080 assertNoErrors(source); |
| 13171 verify([source]); | 13081 verify([source]); |
| 13172 CompilationUnit unit = resolveCompilationUnit(source, library); | 13082 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 13173 SimpleIdentifier identifier = EngineTestCase.findNode( | 13083 SimpleIdentifier identifier = EngineTestCase.findNode( |
| 13174 unit, code, "context", (node) => node is SimpleIdentifier); | 13084 unit, code, "context", (node) => node is SimpleIdentifier); |
| 13175 expect(identifier.propagatedType.name, "CanvasRenderingContext2D"); | 13085 expect(identifier.propagatedType.name, "CanvasRenderingContext2D"); |
| 13176 } | 13086 } |
| 13177 | 13087 |
| 13088 void test_finalPropertyInducingVariable_classMember_instance() { |
| 13089 // TODO(scheglov) remove after switching to the task model |
| 13090 if (!AnalysisEngine.instance.useTaskModel) return; |
| 13091 addNamedSource( |
| 13092 "/lib.dart", |
| 13093 r''' |
| 13094 class A { |
| 13095 final v = 0; |
| 13096 }'''); |
| 13097 String code = r''' |
| 13098 import 'lib.dart'; |
| 13099 f(A a) { |
| 13100 return a.v; // marker |
| 13101 }'''; |
| 13102 _assertTypeOfMarkedExpression( |
| 13103 code, typeProvider.dynamicType, typeProvider.intType); |
| 13104 } |
| 13105 |
| 13106 void test_finalPropertyInducingVariable_classMember_instance_inherited() { |
| 13107 // TODO(scheglov) remove after switching to the task model |
| 13108 if (!AnalysisEngine.instance.useTaskModel) return; |
| 13109 addNamedSource( |
| 13110 "/lib.dart", |
| 13111 r''' |
| 13112 class A { |
| 13113 final v = 0; |
| 13114 }'''); |
| 13115 String code = r''' |
| 13116 import 'lib.dart'; |
| 13117 class B extends A { |
| 13118 m() { |
| 13119 return v; // marker |
| 13120 } |
| 13121 }'''; |
| 13122 _assertTypeOfMarkedExpression( |
| 13123 code, typeProvider.dynamicType, typeProvider.intType); |
| 13124 } |
| 13125 |
| 13126 void test_finalPropertyInducingVariable_classMember_instance_propagatedTarget(
) { |
| 13127 // TODO(scheglov) remove after switching to the task model |
| 13128 if (!AnalysisEngine.instance.useTaskModel) return; |
| 13129 addNamedSource( |
| 13130 "/lib.dart", |
| 13131 r''' |
| 13132 class A { |
| 13133 final v = 0; |
| 13134 }'''); |
| 13135 String code = r''' |
| 13136 import 'lib.dart'; |
| 13137 f(p) { |
| 13138 if (p is A) { |
| 13139 return p.v; // marker |
| 13140 } |
| 13141 }'''; |
| 13142 _assertTypeOfMarkedExpression( |
| 13143 code, typeProvider.dynamicType, typeProvider.intType); |
| 13144 } |
| 13145 |
| 13178 void test_finalPropertyInducingVariable_classMember_instance_unprefixed() { | 13146 void test_finalPropertyInducingVariable_classMember_instance_unprefixed() { |
| 13147 // TODO(scheglov) remove after switching to the task model |
| 13148 if (!AnalysisEngine.instance.useTaskModel) return; |
| 13179 String code = r''' | 13149 String code = r''' |
| 13180 class A { | 13150 class A { |
| 13181 final v = 0; | 13151 final v = 0; |
| 13182 m() { | 13152 m() { |
| 13183 v; // marker | 13153 v; // marker |
| 13184 } | 13154 } |
| 13185 }'''; | 13155 }'''; |
| 13186 _assertTypeOfMarkedExpression( | 13156 _assertTypeOfMarkedExpression( |
| 13187 code, typeProvider.dynamicType, typeProvider.intType); | 13157 code, typeProvider.dynamicType, typeProvider.intType); |
| 13188 } | 13158 } |
| 13189 | 13159 |
| 13160 void test_finalPropertyInducingVariable_classMember_static() { |
| 13161 // TODO(scheglov) remove after switching to the task model |
| 13162 if (!AnalysisEngine.instance.useTaskModel) return; |
| 13163 addNamedSource( |
| 13164 "/lib.dart", |
| 13165 r''' |
| 13166 class A { |
| 13167 static final V = 0; |
| 13168 }'''); |
| 13169 String code = r''' |
| 13170 import 'lib.dart'; |
| 13171 f() { |
| 13172 return A.V; // marker |
| 13173 }'''; |
| 13174 _assertTypeOfMarkedExpression( |
| 13175 code, typeProvider.dynamicType, typeProvider.intType); |
| 13176 } |
| 13177 |
| 13178 void test_finalPropertyInducingVariable_topLevelVariable_prefixed() { |
| 13179 // TODO(scheglov) remove after switching to the task model |
| 13180 if (!AnalysisEngine.instance.useTaskModel) return; |
| 13181 addNamedSource("/lib.dart", "final V = 0;"); |
| 13182 String code = r''' |
| 13183 import 'lib.dart' as p; |
| 13184 f() { |
| 13185 var v2 = p.V; // marker prefixed |
| 13186 }'''; |
| 13187 _assertTypeOfMarkedExpression( |
| 13188 code, typeProvider.dynamicType, typeProvider.intType); |
| 13189 } |
| 13190 |
| 13191 void test_finalPropertyInducingVariable_topLevelVariable_simple() { |
| 13192 // TODO(scheglov) remove after switching to the task model |
| 13193 if (!AnalysisEngine.instance.useTaskModel) return; |
| 13194 addNamedSource("/lib.dart", "final V = 0;"); |
| 13195 String code = r''' |
| 13196 import 'lib.dart'; |
| 13197 f() { |
| 13198 return V; // marker simple |
| 13199 }'''; |
| 13200 _assertTypeOfMarkedExpression( |
| 13201 code, typeProvider.dynamicType, typeProvider.intType); |
| 13202 } |
| 13203 |
| 13190 void test_forEach() { | 13204 void test_forEach() { |
| 13191 String code = r''' | 13205 String code = r''' |
| 13192 main() { | 13206 main() { |
| 13193 var list = <String> []; | 13207 var list = <String> []; |
| 13194 for (var e in list) { | 13208 for (var e in list) { |
| 13195 e; | 13209 e; |
| 13196 } | 13210 } |
| 13197 }'''; | 13211 }'''; |
| 13198 Source source = addSource(code); | 13212 Source source = addSource(code); |
| 13199 LibraryElement library = resolve2(source); | 13213 LibraryElement library = resolve2(source); |
| (...skipping 1993 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15193 | 15207 |
| 15194 void _resolveTestUnit(String code) { | 15208 void _resolveTestUnit(String code) { |
| 15195 testCode = code; | 15209 testCode = code; |
| 15196 testSource = addSource(testCode); | 15210 testSource = addSource(testCode); |
| 15197 LibraryElement library = resolve2(testSource); | 15211 LibraryElement library = resolve2(testSource); |
| 15198 assertNoErrors(testSource); | 15212 assertNoErrors(testSource); |
| 15199 verify([testSource]); | 15213 verify([testSource]); |
| 15200 testUnit = resolveCompilationUnit(testSource, library); | 15214 testUnit = resolveCompilationUnit(testSource, library); |
| 15201 } | 15215 } |
| 15202 } | 15216 } |
| OLD | NEW |