Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(237)

Side by Side Diff: pkg/analyzer/test/generated/resolver_test.dart

Issue 2624793002: Make error producing tests ansynchronous. (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 analyzer.test.generated.resolver_test; 5 library analyzer.test.generated.resolver_test;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analyzer/dart/ast/ast.dart'; 9 import 'package:analyzer/dart/ast/ast.dart';
10 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; 10 import 'package:analyzer/dart/ast/standard_resolution_map.dart';
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 defineReflectiveTests(TypeResolverVisitorTest); 53 defineReflectiveTests(TypeResolverVisitorTest);
54 }); 54 });
55 } 55 }
56 56
57 @reflectiveTest 57 @reflectiveTest
58 class AnalysisDeltaTest extends EngineTestCase { 58 class AnalysisDeltaTest extends EngineTestCase {
59 TestSource source1 = new TestSource('/1.dart'); 59 TestSource source1 = new TestSource('/1.dart');
60 TestSource source2 = new TestSource('/2.dart'); 60 TestSource source2 = new TestSource('/2.dart');
61 TestSource source3 = new TestSource('/3.dart'); 61 TestSource source3 = new TestSource('/3.dart');
62 62
63 void test_getAddedSources() { 63 test_getAddedSources() async {
64 AnalysisDelta delta = new AnalysisDelta(); 64 AnalysisDelta delta = new AnalysisDelta();
65 delta.setAnalysisLevel(source1, AnalysisLevel.ALL); 65 delta.setAnalysisLevel(source1, AnalysisLevel.ALL);
66 delta.setAnalysisLevel(source2, AnalysisLevel.ERRORS); 66 delta.setAnalysisLevel(source2, AnalysisLevel.ERRORS);
67 delta.setAnalysisLevel(source3, AnalysisLevel.NONE); 67 delta.setAnalysisLevel(source3, AnalysisLevel.NONE);
68 List<Source> addedSources = delta.addedSources; 68 List<Source> addedSources = delta.addedSources;
69 expect(addedSources, hasLength(2)); 69 expect(addedSources, hasLength(2));
70 expect(addedSources, unorderedEquals([source1, source2])); 70 expect(addedSources, unorderedEquals([source1, source2]));
71 } 71 }
72 72
73 void test_getAnalysisLevels() { 73 test_getAnalysisLevels() async {
74 AnalysisDelta delta = new AnalysisDelta(); 74 AnalysisDelta delta = new AnalysisDelta();
75 expect(delta.analysisLevels.length, 0); 75 expect(delta.analysisLevels.length, 0);
76 } 76 }
77 77
78 void test_setAnalysisLevel() { 78 test_setAnalysisLevel() async {
79 AnalysisDelta delta = new AnalysisDelta(); 79 AnalysisDelta delta = new AnalysisDelta();
80 delta.setAnalysisLevel(source1, AnalysisLevel.ALL); 80 delta.setAnalysisLevel(source1, AnalysisLevel.ALL);
81 delta.setAnalysisLevel(source2, AnalysisLevel.ERRORS); 81 delta.setAnalysisLevel(source2, AnalysisLevel.ERRORS);
82 Map<Source, AnalysisLevel> levels = delta.analysisLevels; 82 Map<Source, AnalysisLevel> levels = delta.analysisLevels;
83 expect(levels.length, 2); 83 expect(levels.length, 2);
84 expect(levels[source1], AnalysisLevel.ALL); 84 expect(levels[source1], AnalysisLevel.ALL);
85 expect(levels[source2], AnalysisLevel.ERRORS); 85 expect(levels[source2], AnalysisLevel.ERRORS);
86 } 86 }
87 87
88 void test_toString() { 88 test_toString() async {
89 AnalysisDelta delta = new AnalysisDelta(); 89 AnalysisDelta delta = new AnalysisDelta();
90 delta.setAnalysisLevel(new TestSource(), AnalysisLevel.ALL); 90 delta.setAnalysisLevel(new TestSource(), AnalysisLevel.ALL);
91 String result = delta.toString(); 91 String result = delta.toString();
92 expect(result, isNotNull); 92 expect(result, isNotNull);
93 expect(result.length > 0, isTrue); 93 expect(result.length > 0, isTrue);
94 } 94 }
95 } 95 }
96 96
97 @reflectiveTest 97 @reflectiveTest
98 class ChangeSetTest extends EngineTestCase { 98 class ChangeSetTest extends EngineTestCase {
99 void test_changedContent() { 99 test_changedContent() async {
100 TestSource source = new TestSource(); 100 TestSource source = new TestSource();
101 String content = ""; 101 String content = "";
102 ChangeSet changeSet = new ChangeSet(); 102 ChangeSet changeSet = new ChangeSet();
103 changeSet.changedContent(source, content); 103 changeSet.changedContent(source, content);
104 expect(changeSet.addedSources, hasLength(0)); 104 expect(changeSet.addedSources, hasLength(0));
105 expect(changeSet.changedSources, hasLength(0)); 105 expect(changeSet.changedSources, hasLength(0));
106 Map<Source, String> map = changeSet.changedContents; 106 Map<Source, String> map = changeSet.changedContents;
107 expect(map, hasLength(1)); 107 expect(map, hasLength(1));
108 expect(map[source], same(content)); 108 expect(map[source], same(content));
109 expect(changeSet.changedRanges, hasLength(0)); 109 expect(changeSet.changedRanges, hasLength(0));
110 expect(changeSet.removedSources, hasLength(0)); 110 expect(changeSet.removedSources, hasLength(0));
111 expect(changeSet.removedContainers, hasLength(0)); 111 expect(changeSet.removedContainers, hasLength(0));
112 } 112 }
113 113
114 void test_changedRange() { 114 test_changedRange() async {
115 TestSource source = new TestSource(); 115 TestSource source = new TestSource();
116 String content = ""; 116 String content = "";
117 ChangeSet changeSet = new ChangeSet(); 117 ChangeSet changeSet = new ChangeSet();
118 changeSet.changedRange(source, content, 1, 2, 3); 118 changeSet.changedRange(source, content, 1, 2, 3);
119 expect(changeSet.addedSources, hasLength(0)); 119 expect(changeSet.addedSources, hasLength(0));
120 expect(changeSet.changedSources, hasLength(0)); 120 expect(changeSet.changedSources, hasLength(0));
121 expect(changeSet.changedContents, hasLength(0)); 121 expect(changeSet.changedContents, hasLength(0));
122 Map<Source, ChangeSet_ContentChange> map = changeSet.changedRanges; 122 Map<Source, ChangeSet_ContentChange> map = changeSet.changedRanges;
123 expect(map, hasLength(1)); 123 expect(map, hasLength(1));
124 ChangeSet_ContentChange change = map[source]; 124 ChangeSet_ContentChange change = map[source];
125 expect(change, isNotNull); 125 expect(change, isNotNull);
126 expect(change.contents, content); 126 expect(change.contents, content);
127 expect(change.offset, 1); 127 expect(change.offset, 1);
128 expect(change.oldLength, 2); 128 expect(change.oldLength, 2);
129 expect(change.newLength, 3); 129 expect(change.newLength, 3);
130 expect(changeSet.removedSources, hasLength(0)); 130 expect(changeSet.removedSources, hasLength(0));
131 expect(changeSet.removedContainers, hasLength(0)); 131 expect(changeSet.removedContainers, hasLength(0));
132 } 132 }
133 133
134 void test_toString() { 134 test_toString() async {
135 ChangeSet changeSet = new ChangeSet(); 135 ChangeSet changeSet = new ChangeSet();
136 changeSet.addedSource(new TestSource()); 136 changeSet.addedSource(new TestSource());
137 changeSet.changedSource(new TestSource()); 137 changeSet.changedSource(new TestSource());
138 changeSet.changedContent(new TestSource(), ""); 138 changeSet.changedContent(new TestSource(), "");
139 changeSet.changedRange(new TestSource(), "", 0, 0, 0); 139 changeSet.changedRange(new TestSource(), "", 0, 0, 0);
140 changeSet.removedSource(new TestSource()); 140 changeSet.removedSource(new TestSource());
141 changeSet 141 changeSet
142 .removedContainer(new SourceContainer_ChangeSetTest_test_toString()); 142 .removedContainer(new SourceContainer_ChangeSetTest_test_toString());
143 expect(changeSet.toString(), isNotNull); 143 expect(changeSet.toString(), isNotNull);
144 } 144 }
145 } 145 }
146 146
147 @reflectiveTest 147 @reflectiveTest
148 class EnclosedScopeTest extends ResolverTestCase { 148 class EnclosedScopeTest extends ResolverTestCase {
149 void test_define_duplicate() { 149 test_define_duplicate() async {
150 Scope rootScope = new _RootScope(); 150 Scope rootScope = new _RootScope();
151 EnclosedScope scope = new EnclosedScope(rootScope); 151 EnclosedScope scope = new EnclosedScope(rootScope);
152 SimpleIdentifier identifier = AstTestFactory.identifier3('v'); 152 SimpleIdentifier identifier = AstTestFactory.identifier3('v');
153 VariableElement element1 = ElementFactory.localVariableElement(identifier); 153 VariableElement element1 = ElementFactory.localVariableElement(identifier);
154 VariableElement element2 = ElementFactory.localVariableElement(identifier); 154 VariableElement element2 = ElementFactory.localVariableElement(identifier);
155 scope.define(element1); 155 scope.define(element1);
156 scope.define(element2); 156 scope.define(element2);
157 expect(scope.lookup(identifier, null), same(element1)); 157 expect(scope.lookup(identifier, null), same(element1));
158 } 158 }
159 } 159 }
160 160
161 @reflectiveTest 161 @reflectiveTest
162 class ErrorResolverTest extends ResolverTestCase { 162 class ErrorResolverTest extends ResolverTestCase {
163 void test_breakLabelOnSwitchMember() { 163 test_breakLabelOnSwitchMember() async {
164 Source source = addSource(r''' 164 Source source = addSource(r'''
165 class A { 165 class A {
166 void m(int i) { 166 void m(int i) {
167 switch (i) { 167 switch (i) {
168 l: case 0: 168 l: case 0:
169 break; 169 break;
170 case 1: 170 case 1:
171 break l; 171 break l;
172 } 172 }
173 } 173 }
174 }'''); 174 }''');
175 assertErrors(source, [ResolverErrorCode.BREAK_LABEL_ON_SWITCH_MEMBER]); 175 await assertErrors(
176 source, [ResolverErrorCode.BREAK_LABEL_ON_SWITCH_MEMBER]);
176 verify([source]); 177 verify([source]);
177 } 178 }
178 179
179 void test_continueLabelOnSwitch() { 180 test_continueLabelOnSwitch() async {
180 Source source = addSource(r''' 181 Source source = addSource(r'''
181 class A { 182 class A {
182 void m(int i) { 183 void m(int i) {
183 l: switch (i) { 184 l: switch (i) {
184 case 0: 185 case 0:
185 continue l; 186 continue l;
186 } 187 }
187 } 188 }
188 }'''); 189 }''');
189 assertErrors(source, [ResolverErrorCode.CONTINUE_LABEL_ON_SWITCH]); 190 await assertErrors(source, [ResolverErrorCode.CONTINUE_LABEL_ON_SWITCH]);
190 verify([source]); 191 verify([source]);
191 } 192 }
192 193
193 void test_enclosingElement_invalidLocalFunction() { 194 test_enclosingElement_invalidLocalFunction() async {
194 Source source = addSource(r''' 195 Source source = addSource(r'''
195 class C { 196 class C {
196 C() { 197 C() {
197 int get x => 0; 198 int get x => 0;
198 } 199 }
199 }'''); 200 }''');
200 LibraryElement library = resolve2(source); 201 LibraryElement library = resolve2(source);
201 expect(library, isNotNull); 202 expect(library, isNotNull);
202 var unit = library.definingCompilationUnit; 203 var unit = library.definingCompilationUnit;
203 expect(unit, isNotNull); 204 expect(unit, isNotNull);
204 var types = unit.types; 205 var types = unit.types;
205 expect(types, isNotNull); 206 expect(types, isNotNull);
206 expect(types, hasLength(1)); 207 expect(types, hasLength(1));
207 var type = types[0]; 208 var type = types[0];
208 expect(type, isNotNull); 209 expect(type, isNotNull);
209 var constructors = type.constructors; 210 var constructors = type.constructors;
210 expect(constructors, isNotNull); 211 expect(constructors, isNotNull);
211 expect(constructors, hasLength(1)); 212 expect(constructors, hasLength(1));
212 ConstructorElement constructor = constructors[0]; 213 ConstructorElement constructor = constructors[0];
213 expect(constructor, isNotNull); 214 expect(constructor, isNotNull);
214 List<FunctionElement> functions = constructor.functions; 215 List<FunctionElement> functions = constructor.functions;
215 expect(functions, isNotNull); 216 expect(functions, isNotNull);
216 expect(functions, hasLength(1)); 217 expect(functions, hasLength(1));
217 expect(functions[0].enclosingElement, constructor); 218 expect(functions[0].enclosingElement, constructor);
218 assertErrors(source, [ParserErrorCode.GETTER_IN_FUNCTION]); 219 await assertErrors(source, [ParserErrorCode.GETTER_IN_FUNCTION]);
219 } 220 }
220 } 221 }
221 222
222 /** 223 /**
223 * Tests for generic method and function resolution that do not use strong mode. 224 * Tests for generic method and function resolution that do not use strong mode.
224 */ 225 */
225 @reflectiveTest 226 @reflectiveTest
226 class GenericMethodResolverTest extends StaticTypeAnalyzer2TestShared { 227 class GenericMethodResolverTest extends StaticTypeAnalyzer2TestShared {
227 void test_genericMethod_propagatedType_promotion() { 228 test_genericMethod_propagatedType_promotion() async {
228 // Regression test for: 229 // Regression test for:
229 // https://github.com/dart-lang/sdk/issues/25340 230 // https://github.com/dart-lang/sdk/issues/25340
230 // 231 //
231 // Note, after https://github.com/dart-lang/sdk/issues/25486 the original 232 // Note, after https://github.com/dart-lang/sdk/issues/25486 the original
232 // strong mode example won't work, as we now compute a static type and 233 // strong mode example won't work, as we now compute a static type and
233 // therefore discard the propagated type. 234 // therefore discard the propagated type.
234 // 235 //
235 // So this test does not use strong mode. 236 // So this test does not use strong mode.
236 resolveTestUnit(r''' 237 await resolveTestUnit(r'''
237 abstract class Iter { 238 abstract class Iter {
238 List<S> map<S>(S f(x)); 239 List<S> map<S>(S f(x));
239 } 240 }
240 class C {} 241 class C {}
241 C toSpan(dynamic element) { 242 C toSpan(dynamic element) {
242 if (element is Iter) { 243 if (element is Iter) {
243 var y = element.map(toSpan); 244 var y = element.map(toSpan);
244 } 245 }
245 return null; 246 return null;
246 }'''); 247 }''');
247 expectIdentifierType('y = ', 'dynamic', 'List<dynamic>'); 248 expectIdentifierType('y = ', 'dynamic', 'List<dynamic>');
248 } 249 }
249 } 250 }
250 251
251 @reflectiveTest 252 @reflectiveTest
252 class LibraryImportScopeTest extends ResolverTestCase { 253 class LibraryImportScopeTest extends ResolverTestCase {
253 void test_creation_empty() { 254 test_creation_empty() async {
254 new LibraryImportScope(createDefaultTestLibrary()); 255 new LibraryImportScope(createDefaultTestLibrary());
255 } 256 }
256 257
257 void test_creation_nonEmpty() { 258 test_creation_nonEmpty() async {
258 AnalysisContext context = AnalysisContextFactory.contextWithCore(); 259 AnalysisContext context = AnalysisContextFactory.contextWithCore();
259 String importedTypeName = "A"; 260 String importedTypeName = "A";
260 ClassElement importedType = new ClassElementImpl.forNode( 261 ClassElement importedType = new ClassElementImpl.forNode(
261 AstTestFactory.identifier3(importedTypeName)); 262 AstTestFactory.identifier3(importedTypeName));
262 LibraryElement importedLibrary = createTestLibrary(context, "imported"); 263 LibraryElement importedLibrary = createTestLibrary(context, "imported");
263 (importedLibrary.definingCompilationUnit as CompilationUnitElementImpl) 264 (importedLibrary.definingCompilationUnit as CompilationUnitElementImpl)
264 .types = <ClassElement>[importedType]; 265 .types = <ClassElement>[importedType];
265 LibraryElementImpl definingLibrary = 266 LibraryElementImpl definingLibrary =
266 createTestLibrary(context, "importing"); 267 createTestLibrary(context, "importing");
267 ImportElementImpl importElement = new ImportElementImpl(0); 268 ImportElementImpl importElement = new ImportElementImpl(0);
268 importElement.importedLibrary = importedLibrary; 269 importElement.importedLibrary = importedLibrary;
269 definingLibrary.imports = <ImportElement>[importElement]; 270 definingLibrary.imports = <ImportElement>[importElement];
270 Scope scope = new LibraryImportScope(definingLibrary); 271 Scope scope = new LibraryImportScope(definingLibrary);
271 expect( 272 expect(
272 scope.lookup( 273 scope.lookup(
273 AstTestFactory.identifier3(importedTypeName), definingLibrary), 274 AstTestFactory.identifier3(importedTypeName), definingLibrary),
274 importedType); 275 importedType);
275 } 276 }
276 277
277 void test_prefixedAndNonPrefixed() { 278 test_prefixedAndNonPrefixed() async {
278 AnalysisContext context = AnalysisContextFactory.contextWithCore(); 279 AnalysisContext context = AnalysisContextFactory.contextWithCore();
279 String typeName = "C"; 280 String typeName = "C";
280 String prefixName = "p"; 281 String prefixName = "p";
281 ClassElement prefixedType = ElementFactory.classElement2(typeName); 282 ClassElement prefixedType = ElementFactory.classElement2(typeName);
282 ClassElement nonPrefixedType = ElementFactory.classElement2(typeName); 283 ClassElement nonPrefixedType = ElementFactory.classElement2(typeName);
283 LibraryElement prefixedLibrary = 284 LibraryElement prefixedLibrary =
284 createTestLibrary(context, "import.prefixed"); 285 createTestLibrary(context, "import.prefixed");
285 (prefixedLibrary.definingCompilationUnit as CompilationUnitElementImpl) 286 (prefixedLibrary.definingCompilationUnit as CompilationUnitElementImpl)
286 .types = <ClassElement>[prefixedType]; 287 .types = <ClassElement>[prefixedType];
287 ImportElementImpl prefixedImport = ElementFactory.importFor( 288 ImportElementImpl prefixedImport = ElementFactory.importFor(
(...skipping 15 matching lines...) Expand all
303 AstTestFactory.identifier5(prefixName, typeName), importingLibrary); 304 AstTestFactory.identifier5(prefixName, typeName), importingLibrary);
304 expect(prefixedElement, same(prefixedType)); 305 expect(prefixedElement, same(prefixedType));
305 Element nonPrefixedElement = 306 Element nonPrefixedElement =
306 scope.lookup(AstTestFactory.identifier3(typeName), importingLibrary); 307 scope.lookup(AstTestFactory.identifier3(typeName), importingLibrary);
307 expect(nonPrefixedElement, same(nonPrefixedType)); 308 expect(nonPrefixedElement, same(nonPrefixedType));
308 } 309 }
309 } 310 }
310 311
311 @reflectiveTest 312 @reflectiveTest
312 class LibraryScopeTest extends ResolverTestCase { 313 class LibraryScopeTest extends ResolverTestCase {
313 void test_creation_empty() { 314 test_creation_empty() async {
314 new LibraryScope(createDefaultTestLibrary()); 315 new LibraryScope(createDefaultTestLibrary());
315 } 316 }
316 317
317 void test_creation_nonEmpty() { 318 test_creation_nonEmpty() async {
318 AnalysisContext context = AnalysisContextFactory.contextWithCore(); 319 AnalysisContext context = AnalysisContextFactory.contextWithCore();
319 String importedTypeName = "A"; 320 String importedTypeName = "A";
320 ClassElement importedType = new ClassElementImpl.forNode( 321 ClassElement importedType = new ClassElementImpl.forNode(
321 AstTestFactory.identifier3(importedTypeName)); 322 AstTestFactory.identifier3(importedTypeName));
322 LibraryElement importedLibrary = createTestLibrary(context, "imported"); 323 LibraryElement importedLibrary = createTestLibrary(context, "imported");
323 (importedLibrary.definingCompilationUnit as CompilationUnitElementImpl) 324 (importedLibrary.definingCompilationUnit as CompilationUnitElementImpl)
324 .types = <ClassElement>[importedType]; 325 .types = <ClassElement>[importedType];
325 LibraryElementImpl definingLibrary = 326 LibraryElementImpl definingLibrary =
326 createTestLibrary(context, "importing"); 327 createTestLibrary(context, "importing");
327 ImportElementImpl importElement = new ImportElementImpl(0); 328 ImportElementImpl importElement = new ImportElementImpl(0);
328 importElement.importedLibrary = importedLibrary; 329 importElement.importedLibrary = importedLibrary;
329 definingLibrary.imports = <ImportElement>[importElement]; 330 definingLibrary.imports = <ImportElement>[importElement];
330 Scope scope = new LibraryScope(definingLibrary); 331 Scope scope = new LibraryScope(definingLibrary);
331 expect( 332 expect(
332 scope.lookup( 333 scope.lookup(
333 AstTestFactory.identifier3(importedTypeName), definingLibrary), 334 AstTestFactory.identifier3(importedTypeName), definingLibrary),
334 importedType); 335 importedType);
335 } 336 }
336 } 337 }
337 338
338 @reflectiveTest 339 @reflectiveTest
339 class PrefixedNamespaceTest extends ResolverTestCase { 340 class PrefixedNamespaceTest extends ResolverTestCase {
340 void test_lookup_missing() { 341 test_lookup_missing() async {
341 ClassElement element = ElementFactory.classElement2('A'); 342 ClassElement element = ElementFactory.classElement2('A');
342 PrefixedNamespace namespace = new PrefixedNamespace('p', _toMap([element])); 343 PrefixedNamespace namespace = new PrefixedNamespace('p', _toMap([element]));
343 expect(namespace.get('p.B'), isNull); 344 expect(namespace.get('p.B'), isNull);
344 } 345 }
345 346
346 void test_lookup_missing_matchesPrefix() { 347 test_lookup_missing_matchesPrefix() async {
347 ClassElement element = ElementFactory.classElement2('A'); 348 ClassElement element = ElementFactory.classElement2('A');
348 PrefixedNamespace namespace = new PrefixedNamespace('p', _toMap([element])); 349 PrefixedNamespace namespace = new PrefixedNamespace('p', _toMap([element]));
349 expect(namespace.get('p'), isNull); 350 expect(namespace.get('p'), isNull);
350 } 351 }
351 352
352 void test_lookup_valid() { 353 test_lookup_valid() async {
353 ClassElement element = ElementFactory.classElement2('A'); 354 ClassElement element = ElementFactory.classElement2('A');
354 PrefixedNamespace namespace = new PrefixedNamespace('p', _toMap([element])); 355 PrefixedNamespace namespace = new PrefixedNamespace('p', _toMap([element]));
355 expect(namespace.get('p.A'), same(element)); 356 expect(namespace.get('p.A'), same(element));
356 } 357 }
357 358
358 HashMap<String, Element> _toMap(List<Element> elements) { 359 HashMap<String, Element> _toMap(List<Element> elements) {
359 HashMap<String, Element> map = new HashMap<String, Element>(); 360 HashMap<String, Element> map = new HashMap<String, Element>();
360 for (Element element in elements) { 361 for (Element element in elements) {
361 map[element.name] = element; 362 map[element.name] = element;
362 } 363 }
363 return map; 364 return map;
364 } 365 }
365 } 366 }
366 367
367 @reflectiveTest 368 @reflectiveTest
368 class ScopeTest extends ResolverTestCase { 369 class ScopeTest extends ResolverTestCase {
369 void test_define_duplicate() { 370 test_define_duplicate() async {
370 Scope scope = new _RootScope(); 371 Scope scope = new _RootScope();
371 SimpleIdentifier identifier = AstTestFactory.identifier3('v'); 372 SimpleIdentifier identifier = AstTestFactory.identifier3('v');
372 VariableElement element1 = ElementFactory.localVariableElement(identifier); 373 VariableElement element1 = ElementFactory.localVariableElement(identifier);
373 VariableElement element2 = ElementFactory.localVariableElement(identifier); 374 VariableElement element2 = ElementFactory.localVariableElement(identifier);
374 scope.define(element1); 375 scope.define(element1);
375 scope.define(element2); 376 scope.define(element2);
376 expect(scope.localLookup('v', null), same(element1)); 377 expect(scope.localLookup('v', null), same(element1));
377 } 378 }
378 379
379 void test_isPrivateName_nonPrivate() { 380 test_isPrivateName_nonPrivate() async {
380 expect(Scope.isPrivateName("Public"), isFalse); 381 expect(Scope.isPrivateName("Public"), isFalse);
381 } 382 }
382 383
383 void test_isPrivateName_private() { 384 test_isPrivateName_private() async {
384 expect(Scope.isPrivateName("_Private"), isTrue); 385 expect(Scope.isPrivateName("_Private"), isTrue);
385 } 386 }
386 } 387 }
387 388
388 class SourceContainer_ChangeSetTest_test_toString implements SourceContainer { 389 class SourceContainer_ChangeSetTest_test_toString implements SourceContainer {
389 @override 390 @override
390 bool contains(Source source) => false; 391 bool contains(Source source) => false;
391 } 392 }
392 393
393 /** 394 /**
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 return "<unknown file- ASTNode is null>"; 607 return "<unknown file- ASTNode is null>";
607 } 608 }
608 } 609 }
609 610
610 /** 611 /**
611 * The class `StrictModeTest` contains tests to ensure that the correct errors a nd warnings 612 * The class `StrictModeTest` contains tests to ensure that the correct errors a nd warnings
612 * are reported when the analysis engine is run in strict mode. 613 * are reported when the analysis engine is run in strict mode.
613 */ 614 */
614 @reflectiveTest 615 @reflectiveTest
615 class StrictModeTest extends ResolverTestCase { 616 class StrictModeTest extends ResolverTestCase {
616 void fail_for() { 617 fail_for() async {
617 Source source = addSource(r''' 618 Source source = addSource(r'''
618 int f(List<int> list) { 619 int f(List<int> list) {
619 num sum = 0; 620 num sum = 0;
620 for (num i = 0; i < list.length; i++) { 621 for (num i = 0; i < list.length; i++) {
621 sum += list[i]; 622 sum += list[i];
622 } 623 }
623 }'''); 624 }''');
624 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]); 625 await assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]);
625 } 626 }
626 627
627 @override 628 @override
628 void setUp() { 629 void setUp() {
629 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); 630 AnalysisOptionsImpl options = new AnalysisOptionsImpl();
630 options.hint = false; 631 options.hint = false;
631 resetWithOptions(options); 632 resetWithOptions(options);
632 } 633 }
633 634
634 void test_assert_is() { 635 test_assert_is() async {
635 Source source = addSource(r''' 636 Source source = addSource(r'''
636 int f(num n) { 637 int f(num n) {
637 assert (n is int); 638 assert (n is int);
638 return n & 0x0F; 639 return n & 0x0F;
639 }'''); 640 }''');
640 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]); 641 await assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]);
641 } 642 }
642 643
643 void test_conditional_and_is() { 644 test_conditional_and_is() async {
644 Source source = addSource(r''' 645 Source source = addSource(r'''
645 int f(num n) { 646 int f(num n) {
646 return (n is int && n > 0) ? n & 0x0F : 0; 647 return (n is int && n > 0) ? n & 0x0F : 0;
647 }'''); 648 }''');
648 assertNoErrors(source); 649 await assertNoErrors(source);
649 } 650 }
650 651
651 void test_conditional_is() { 652 test_conditional_is() async {
652 Source source = addSource(r''' 653 Source source = addSource(r'''
653 int f(num n) { 654 int f(num n) {
654 return (n is int) ? n & 0x0F : 0; 655 return (n is int) ? n & 0x0F : 0;
655 }'''); 656 }''');
656 assertNoErrors(source); 657 await assertNoErrors(source);
657 } 658 }
658 659
659 void test_conditional_isNot() { 660 test_conditional_isNot() async {
660 Source source = addSource(r''' 661 Source source = addSource(r'''
661 int f(num n) { 662 int f(num n) {
662 return (n is! int) ? 0 : n & 0x0F; 663 return (n is! int) ? 0 : n & 0x0F;
663 }'''); 664 }''');
664 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]); 665 await assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]);
665 } 666 }
666 667
667 void test_conditional_or_is() { 668 test_conditional_or_is() async {
668 Source source = addSource(r''' 669 Source source = addSource(r'''
669 int f(num n) { 670 int f(num n) {
670 return (n is! int || n < 0) ? 0 : n & 0x0F; 671 return (n is! int || n < 0) ? 0 : n & 0x0F;
671 }'''); 672 }''');
672 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]); 673 await assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]);
673 } 674 }
674 675
675 void test_forEach() { 676 test_forEach() async {
676 Source source = addSource(r''' 677 Source source = addSource(r'''
677 int f(List<int> list) { 678 int f(List<int> list) {
678 num sum = 0; 679 num sum = 0;
679 for (num n in list) { 680 for (num n in list) {
680 sum += n & 0x0F; 681 sum += n & 0x0F;
681 } 682 }
682 }'''); 683 }''');
683 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]); 684 await assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]);
684 } 685 }
685 686
686 void test_if_and_is() { 687 test_if_and_is() async {
687 Source source = addSource(r''' 688 Source source = addSource(r'''
688 int f(num n) { 689 int f(num n) {
689 if (n is int && n > 0) { 690 if (n is int && n > 0) {
690 return n & 0x0F; 691 return n & 0x0F;
691 } 692 }
692 return 0; 693 return 0;
693 }'''); 694 }''');
694 assertNoErrors(source); 695 await assertNoErrors(source);
695 } 696 }
696 697
697 void test_if_is() { 698 test_if_is() async {
698 Source source = addSource(r''' 699 Source source = addSource(r'''
699 int f(num n) { 700 int f(num n) {
700 if (n is int) { 701 if (n is int) {
701 return n & 0x0F; 702 return n & 0x0F;
702 } 703 }
703 return 0; 704 return 0;
704 }'''); 705 }''');
705 assertNoErrors(source); 706 await assertNoErrors(source);
706 } 707 }
707 708
708 void test_if_isNot() { 709 test_if_isNot() async {
709 Source source = addSource(r''' 710 Source source = addSource(r'''
710 int f(num n) { 711 int f(num n) {
711 if (n is! int) { 712 if (n is! int) {
712 return 0; 713 return 0;
713 } else { 714 } else {
714 return n & 0x0F; 715 return n & 0x0F;
715 } 716 }
716 }'''); 717 }''');
717 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]); 718 await assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]);
718 } 719 }
719 720
720 void test_if_isNot_abrupt() { 721 test_if_isNot_abrupt() async {
721 Source source = addSource(r''' 722 Source source = addSource(r'''
722 int f(num n) { 723 int f(num n) {
723 if (n is! int) { 724 if (n is! int) {
724 return 0; 725 return 0;
725 } 726 }
726 return n & 0x0F; 727 return n & 0x0F;
727 }'''); 728 }''');
728 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]); 729 await assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]);
729 } 730 }
730 731
731 void test_if_or_is() { 732 test_if_or_is() async {
732 Source source = addSource(r''' 733 Source source = addSource(r'''
733 int f(num n) { 734 int f(num n) {
734 if (n is! int || n < 0) { 735 if (n is! int || n < 0) {
735 return 0; 736 return 0;
736 } else { 737 } else {
737 return n & 0x0F; 738 return n & 0x0F;
738 } 739 }
739 }'''); 740 }''');
740 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]); 741 await assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]);
741 } 742 }
742 743
743 void test_localVar() { 744 test_localVar() async {
744 Source source = addSource(r''' 745 Source source = addSource(r'''
745 int f() { 746 int f() {
746 num n = 1234; 747 num n = 1234;
747 return n & 0x0F; 748 return n & 0x0F;
748 }'''); 749 }''');
749 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]); 750 await assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]);
750 } 751 }
751 } 752 }
752 753
753 @reflectiveTest 754 @reflectiveTest
754 class SubtypeManagerTest { 755 class SubtypeManagerTest {
755 /** 756 /**
756 * The inheritance manager being tested. 757 * The inheritance manager being tested.
757 */ 758 */
758 SubtypeManager _subtypeManager; 759 SubtypeManager _subtypeManager;
759 760
760 /** 761 /**
761 * The compilation unit element containing all of the types setup in each test . 762 * The compilation unit element containing all of the types setup in each test .
762 */ 763 */
763 CompilationUnitElementImpl _definingCompilationUnit; 764 CompilationUnitElementImpl _definingCompilationUnit;
764 765
765 void setUp() { 766 void setUp() {
766 MemoryResourceProvider resourceProvider = new MemoryResourceProvider(); 767 MemoryResourceProvider resourceProvider = new MemoryResourceProvider();
767 AnalysisContext context = AnalysisContextFactory.contextWithCore( 768 AnalysisContext context = AnalysisContextFactory.contextWithCore(
768 resourceProvider: resourceProvider); 769 resourceProvider: resourceProvider);
769 Source source = new FileSource(resourceProvider.getFile("/test.dart")); 770 Source source = new FileSource(resourceProvider.getFile("/test.dart"));
770 _definingCompilationUnit = new CompilationUnitElementImpl("test.dart"); 771 _definingCompilationUnit = new CompilationUnitElementImpl("test.dart");
771 _definingCompilationUnit.librarySource = 772 _definingCompilationUnit.librarySource =
772 _definingCompilationUnit.source = source; 773 _definingCompilationUnit.source = source;
773 LibraryElementImpl definingLibrary = 774 LibraryElementImpl definingLibrary =
774 ElementFactory.library(context, "test"); 775 ElementFactory.library(context, "test");
775 definingLibrary.definingCompilationUnit = _definingCompilationUnit; 776 definingLibrary.definingCompilationUnit = _definingCompilationUnit;
776 _subtypeManager = new SubtypeManager(); 777 _subtypeManager = new SubtypeManager();
777 } 778 }
778 779
779 void test_computeAllSubtypes_infiniteLoop() { 780 test_computeAllSubtypes_infiniteLoop() async {
780 // 781 //
781 // class A extends B 782 // class A extends B
782 // class B extends A 783 // class B extends A
783 // 784 //
784 ClassElementImpl classA = ElementFactory.classElement2("A"); 785 ClassElementImpl classA = ElementFactory.classElement2("A");
785 ClassElementImpl classB = ElementFactory.classElement("B", classA.type); 786 ClassElementImpl classB = ElementFactory.classElement("B", classA.type);
786 classA.supertype = classB.type; 787 classA.supertype = classB.type;
787 _definingCompilationUnit.types = <ClassElement>[classA, classB]; 788 _definingCompilationUnit.types = <ClassElement>[classA, classB];
788 HashSet<ClassElement> subtypesOfA = 789 HashSet<ClassElement> subtypesOfA =
789 _subtypeManager.computeAllSubtypes(classA); 790 _subtypeManager.computeAllSubtypes(classA);
790 List<ClassElement> arraySubtypesOfA = new List.from(subtypesOfA); 791 List<ClassElement> arraySubtypesOfA = new List.from(subtypesOfA);
791 expect(subtypesOfA, hasLength(2)); 792 expect(subtypesOfA, hasLength(2));
792 expect(arraySubtypesOfA, unorderedEquals([classA, classB])); 793 expect(arraySubtypesOfA, unorderedEquals([classA, classB]));
793 } 794 }
794 795
795 void test_computeAllSubtypes_manyRecursiveSubtypes() { 796 test_computeAllSubtypes_manyRecursiveSubtypes() async {
796 // 797 //
797 // class A 798 // class A
798 // class B extends A 799 // class B extends A
799 // class C extends B 800 // class C extends B
800 // class D extends B 801 // class D extends B
801 // class E extends B 802 // class E extends B
802 // 803 //
803 ClassElementImpl classA = ElementFactory.classElement2("A"); 804 ClassElementImpl classA = ElementFactory.classElement2("A");
804 ClassElementImpl classB = ElementFactory.classElement("B", classA.type); 805 ClassElementImpl classB = ElementFactory.classElement("B", classA.type);
805 ClassElementImpl classC = ElementFactory.classElement("C", classB.type); 806 ClassElementImpl classC = ElementFactory.classElement("C", classB.type);
(...skipping 11 matching lines...) Expand all
817 List<ClassElement> arraySubtypesOfA = new List.from(subtypesOfA); 818 List<ClassElement> arraySubtypesOfA = new List.from(subtypesOfA);
818 HashSet<ClassElement> subtypesOfB = 819 HashSet<ClassElement> subtypesOfB =
819 _subtypeManager.computeAllSubtypes(classB); 820 _subtypeManager.computeAllSubtypes(classB);
820 List<ClassElement> arraySubtypesOfB = new List.from(subtypesOfB); 821 List<ClassElement> arraySubtypesOfB = new List.from(subtypesOfB);
821 expect(subtypesOfA, hasLength(4)); 822 expect(subtypesOfA, hasLength(4));
822 expect(arraySubtypesOfA, unorderedEquals([classB, classC, classD, classE])); 823 expect(arraySubtypesOfA, unorderedEquals([classB, classC, classD, classE]));
823 expect(subtypesOfB, hasLength(3)); 824 expect(subtypesOfB, hasLength(3));
824 expect(arraySubtypesOfB, unorderedEquals([classC, classD, classE])); 825 expect(arraySubtypesOfB, unorderedEquals([classC, classD, classE]));
825 } 826 }
826 827
827 void test_computeAllSubtypes_noSubtypes() { 828 test_computeAllSubtypes_noSubtypes() async {
828 // 829 //
829 // class A 830 // class A
830 // 831 //
831 ClassElementImpl classA = ElementFactory.classElement2("A"); 832 ClassElementImpl classA = ElementFactory.classElement2("A");
832 _definingCompilationUnit.types = <ClassElement>[classA]; 833 _definingCompilationUnit.types = <ClassElement>[classA];
833 HashSet<ClassElement> subtypesOfA = 834 HashSet<ClassElement> subtypesOfA =
834 _subtypeManager.computeAllSubtypes(classA); 835 _subtypeManager.computeAllSubtypes(classA);
835 expect(subtypesOfA, hasLength(0)); 836 expect(subtypesOfA, hasLength(0));
836 } 837 }
837 838
838 void test_computeAllSubtypes_oneSubtype() { 839 test_computeAllSubtypes_oneSubtype() async {
839 // 840 //
840 // class A 841 // class A
841 // class B extends A 842 // class B extends A
842 // 843 //
843 ClassElementImpl classA = ElementFactory.classElement2("A"); 844 ClassElementImpl classA = ElementFactory.classElement2("A");
844 ClassElementImpl classB = ElementFactory.classElement("B", classA.type); 845 ClassElementImpl classB = ElementFactory.classElement("B", classA.type);
845 _definingCompilationUnit.types = <ClassElement>[classA, classB]; 846 _definingCompilationUnit.types = <ClassElement>[classA, classB];
846 HashSet<ClassElement> subtypesOfA = 847 HashSet<ClassElement> subtypesOfA =
847 _subtypeManager.computeAllSubtypes(classA); 848 _subtypeManager.computeAllSubtypes(classA);
848 List<ClassElement> arraySubtypesOfA = new List.from(subtypesOfA); 849 List<ClassElement> arraySubtypesOfA = new List.from(subtypesOfA);
849 expect(subtypesOfA, hasLength(1)); 850 expect(subtypesOfA, hasLength(1));
850 expect(arraySubtypesOfA, unorderedEquals([classB])); 851 expect(arraySubtypesOfA, unorderedEquals([classB]));
851 } 852 }
852 } 853 }
853 854
854 @reflectiveTest 855 @reflectiveTest
855 class TypeOverrideManagerTest extends EngineTestCase { 856 class TypeOverrideManagerTest extends EngineTestCase {
856 void test_exitScope_noScopes() { 857 test_exitScope_noScopes() async {
857 TypeOverrideManager manager = new TypeOverrideManager(); 858 TypeOverrideManager manager = new TypeOverrideManager();
858 expect(() { 859 expect(() {
859 manager.exitScope(); 860 manager.exitScope();
860 }, throwsStateError); 861 }, throwsStateError);
861 } 862 }
862 863
863 void test_exitScope_oneScope() { 864 test_exitScope_oneScope() async {
864 TypeOverrideManager manager = new TypeOverrideManager(); 865 TypeOverrideManager manager = new TypeOverrideManager();
865 manager.enterScope(); 866 manager.enterScope();
866 manager.exitScope(); 867 manager.exitScope();
867 expect(() { 868 expect(() {
868 manager.exitScope(); 869 manager.exitScope();
869 }, throwsStateError); 870 }, throwsStateError);
870 } 871 }
871 872
872 void test_exitScope_twoScopes() { 873 test_exitScope_twoScopes() async {
873 TypeOverrideManager manager = new TypeOverrideManager(); 874 TypeOverrideManager manager = new TypeOverrideManager();
874 manager.enterScope(); 875 manager.enterScope();
875 manager.exitScope(); 876 manager.exitScope();
876 manager.enterScope(); 877 manager.enterScope();
877 manager.exitScope(); 878 manager.exitScope();
878 expect(() { 879 expect(() {
879 manager.exitScope(); 880 manager.exitScope();
880 }, throwsStateError); 881 }, throwsStateError);
881 } 882 }
882 883
883 void test_getType_enclosedOverride() { 884 test_getType_enclosedOverride() async {
884 TypeOverrideManager manager = new TypeOverrideManager(); 885 TypeOverrideManager manager = new TypeOverrideManager();
885 LocalVariableElementImpl element = 886 LocalVariableElementImpl element =
886 ElementFactory.localVariableElement2("v"); 887 ElementFactory.localVariableElement2("v");
887 InterfaceType type = ElementFactory.classElement2("C").type; 888 InterfaceType type = ElementFactory.classElement2("C").type;
888 manager.enterScope(); 889 manager.enterScope();
889 manager.setType(element, type); 890 manager.setType(element, type);
890 manager.enterScope(); 891 manager.enterScope();
891 expect(manager.getType(element), same(type)); 892 expect(manager.getType(element), same(type));
892 } 893 }
893 894
894 void test_getType_immediateOverride() { 895 test_getType_immediateOverride() async {
895 TypeOverrideManager manager = new TypeOverrideManager(); 896 TypeOverrideManager manager = new TypeOverrideManager();
896 LocalVariableElementImpl element = 897 LocalVariableElementImpl element =
897 ElementFactory.localVariableElement2("v"); 898 ElementFactory.localVariableElement2("v");
898 InterfaceType type = ElementFactory.classElement2("C").type; 899 InterfaceType type = ElementFactory.classElement2("C").type;
899 manager.enterScope(); 900 manager.enterScope();
900 manager.setType(element, type); 901 manager.setType(element, type);
901 expect(manager.getType(element), same(type)); 902 expect(manager.getType(element), same(type));
902 } 903 }
903 904
904 void test_getType_noOverride() { 905 test_getType_noOverride() async {
905 TypeOverrideManager manager = new TypeOverrideManager(); 906 TypeOverrideManager manager = new TypeOverrideManager();
906 manager.enterScope(); 907 manager.enterScope();
907 expect(manager.getType(ElementFactory.localVariableElement2("v")), isNull); 908 expect(manager.getType(ElementFactory.localVariableElement2("v")), isNull);
908 } 909 }
909 910
910 void test_getType_noScope() { 911 test_getType_noScope() async {
911 TypeOverrideManager manager = new TypeOverrideManager(); 912 TypeOverrideManager manager = new TypeOverrideManager();
912 expect(manager.getType(ElementFactory.localVariableElement2("v")), isNull); 913 expect(manager.getType(ElementFactory.localVariableElement2("v")), isNull);
913 } 914 }
914 } 915 }
915 916
916 @reflectiveTest 917 @reflectiveTest
917 class TypePropagationTest extends ResolverTestCase { 918 class TypePropagationTest extends ResolverTestCase {
918 void fail_mergePropagatedTypesAtJoinPoint_1() { 919 fail_mergePropagatedTypesAtJoinPoint_1() async {
919 // https://code.google.com/p/dart/issues/detail?id=19929 920 // https://code.google.com/p/dart/issues/detail?id=19929
920 assertTypeOfMarkedExpression( 921 await assertTypeOfMarkedExpression(
921 r''' 922 r'''
922 f1(x) { 923 f1(x) {
923 var y = []; 924 var y = [];
924 if (x) { 925 if (x) {
925 y = 0; 926 y = 0;
926 } else { 927 } else {
927 y = ''; 928 y = '';
928 } 929 }
929 // Propagated type is [List] here: incorrect. 930 // Propagated type is [List] here: incorrect.
930 // Best we can do is [Object]? 931 // Best we can do is [Object]?
931 return y; // marker 932 return y; // marker
932 }''', 933 }''',
933 null, 934 null,
934 typeProvider.dynamicType); 935 typeProvider.dynamicType);
935 } 936 }
936 937
937 void fail_mergePropagatedTypesAtJoinPoint_2() { 938 fail_mergePropagatedTypesAtJoinPoint_2() async {
938 // https://code.google.com/p/dart/issues/detail?id=19929 939 // https://code.google.com/p/dart/issues/detail?id=19929
939 assertTypeOfMarkedExpression( 940 await assertTypeOfMarkedExpression(
940 r''' 941 r'''
941 f2(x) { 942 f2(x) {
942 var y = []; 943 var y = [];
943 if (x) { 944 if (x) {
944 y = 0; 945 y = 0;
945 } else { 946 } else {
946 } 947 }
947 // Propagated type is [List] here: incorrect. 948 // Propagated type is [List] here: incorrect.
948 // Best we can do is [Object]? 949 // Best we can do is [Object]?
949 return y; // marker 950 return y; // marker
950 }''', 951 }''',
951 null, 952 null,
952 typeProvider.dynamicType); 953 typeProvider.dynamicType);
953 } 954 }
954 955
955 void fail_mergePropagatedTypesAtJoinPoint_3() { 956 fail_mergePropagatedTypesAtJoinPoint_3() async {
956 // https://code.google.com/p/dart/issues/detail?id=19929 957 // https://code.google.com/p/dart/issues/detail?id=19929
957 assertTypeOfMarkedExpression( 958 await assertTypeOfMarkedExpression(
958 r''' 959 r'''
959 f4(x) { 960 f4(x) {
960 var y = []; 961 var y = [];
961 if (x) { 962 if (x) {
962 y = 0; 963 y = 0;
963 } else { 964 } else {
964 y = 1.5; 965 y = 1.5;
965 } 966 }
966 // Propagated type is [List] here: incorrect. 967 // Propagated type is [List] here: incorrect.
967 // A correct answer is the least upper bound of [int] and [double], 968 // A correct answer is the least upper bound of [int] and [double],
968 // i.e. [num]. 969 // i.e. [num].
969 return y; // marker 970 return y; // marker
970 }''', 971 }''',
971 null, 972 null,
972 typeProvider.numType); 973 typeProvider.numType);
973 } 974 }
974 975
975 void fail_mergePropagatedTypesAtJoinPoint_5() { 976 fail_mergePropagatedTypesAtJoinPoint_5() async {
976 // https://code.google.com/p/dart/issues/detail?id=19929 977 // https://code.google.com/p/dart/issues/detail?id=19929
977 assertTypeOfMarkedExpression( 978 await assertTypeOfMarkedExpression(
978 r''' 979 r'''
979 f6(x,y) { 980 f6(x,y) {
980 var z = []; 981 var z = [];
981 if (x || (z = y) < 0) { 982 if (x || (z = y) < 0) {
982 } else { 983 } else {
983 z = 0; 984 z = 0;
984 } 985 }
985 // Propagated type is [List] here: incorrect. 986 // Propagated type is [List] here: incorrect.
986 // Best we can do is [Object]? 987 // Best we can do is [Object]?
987 return z; // marker 988 return z; // marker
988 }''', 989 }''',
989 null, 990 null,
990 typeProvider.dynamicType); 991 typeProvider.dynamicType);
991 } 992 }
992 993
993 void fail_mergePropagatedTypesAtJoinPoint_7() { 994 fail_mergePropagatedTypesAtJoinPoint_7() async {
994 // https://code.google.com/p/dart/issues/detail?id=19929 995 // https://code.google.com/p/dart/issues/detail?id=19929
995 // 996 //
996 // In general [continue]s are unsafe for the purposes of 997 // In general [continue]s are unsafe for the purposes of
997 // [isAbruptTerminationStatement]. 998 // [isAbruptTerminationStatement].
998 // 999 //
999 // This is like example 6, but less tricky: the code in the branch that 1000 // This is like example 6, but less tricky: the code in the branch that
1000 // [continue]s is in effect after the [if]. 1001 // [continue]s is in effect after the [if].
1001 String code = r''' 1002 String code = r'''
1002 f() { 1003 f() {
1003 var x = 0; 1004 var x = 0;
1004 var c = false; 1005 var c = false;
1005 var d = true; 1006 var d = true;
1006 while (d) { 1007 while (d) {
1007 if (c) { 1008 if (c) {
1008 d = false; 1009 d = false;
1009 } else { 1010 } else {
1010 x = ''; 1011 x = '';
1011 c = true; 1012 c = true;
1012 continue; 1013 continue;
1013 } 1014 }
1014 x; // marker 1015 x; // marker
1015 } 1016 }
1016 }'''; 1017 }''';
1017 DartType t = findMarkedIdentifier(code, "; // marker").propagatedType; 1018 DartType t =
1019 (await findMarkedIdentifier(code, "; // marker")).propagatedType;
1018 expect(typeProvider.intType.isSubtypeOf(t), isTrue); 1020 expect(typeProvider.intType.isSubtypeOf(t), isTrue);
1019 expect(typeProvider.stringType.isSubtypeOf(t), isTrue); 1021 expect(typeProvider.stringType.isSubtypeOf(t), isTrue);
1020 } 1022 }
1021 1023
1022 void fail_mergePropagatedTypesAtJoinPoint_8() { 1024 fail_mergePropagatedTypesAtJoinPoint_8() async {
1023 // https://code.google.com/p/dart/issues/detail?id=19929 1025 // https://code.google.com/p/dart/issues/detail?id=19929
1024 // 1026 //
1025 // In nested loops [breaks]s are unsafe for the purposes of 1027 // In nested loops [breaks]s are unsafe for the purposes of
1026 // [isAbruptTerminationStatement]. 1028 // [isAbruptTerminationStatement].
1027 // 1029 //
1028 // This is a combination of 6 and 7: we use an unlabeled [break] 1030 // This is a combination of 6 and 7: we use an unlabeled [break]
1029 // like a continue for the outer loop / like a labeled [break] to 1031 // like a continue for the outer loop / like a labeled [break] to
1030 // jump just above the [if]. 1032 // jump just above the [if].
1031 String code = r''' 1033 String code = r'''
1032 f() { 1034 f() {
1033 var x = 0; 1035 var x = 0;
1034 var c = false; 1036 var c = false;
1035 var d = true; 1037 var d = true;
1036 while (d) { 1038 while (d) {
1037 while (d) { 1039 while (d) {
1038 if (c) { 1040 if (c) {
1039 d = false; 1041 d = false;
1040 } else { 1042 } else {
1041 x = ''; 1043 x = '';
1042 c = true; 1044 c = true;
1043 break; 1045 break;
1044 } 1046 }
1045 x; // marker 1047 x; // marker
1046 } 1048 }
1047 } 1049 }
1048 }'''; 1050 }''';
1049 DartType t = findMarkedIdentifier(code, "; // marker").propagatedType; 1051 DartType t =
1052 (await findMarkedIdentifier(code, "; // marker")).propagatedType;
1050 expect(typeProvider.intType.isSubtypeOf(t), isTrue); 1053 expect(typeProvider.intType.isSubtypeOf(t), isTrue);
1051 expect(typeProvider.stringType.isSubtypeOf(t), isTrue); 1054 expect(typeProvider.stringType.isSubtypeOf(t), isTrue);
1052 } 1055 }
1053 1056
1054 void fail_propagatedReturnType_functionExpression() { 1057 fail_propagatedReturnType_functionExpression() async {
1055 // TODO(scheglov) disabled because we don't resolve function expression 1058 // TODO(scheglov) disabled because we don't resolve function expression
1056 String code = r''' 1059 String code = r'''
1057 main() { 1060 main() {
1058 var v = (() {return 42;})(); 1061 var v = (() {return 42;})();
1059 }'''; 1062 }''';
1060 assertPropagatedAssignedType( 1063 await assertPropagatedAssignedType(
1061 code, typeProvider.dynamicType, typeProvider.intType); 1064 code, typeProvider.dynamicType, typeProvider.intType);
1062 } 1065 }
1063 1066
1064 void test_as() { 1067 test_as() async {
1065 Source source = addSource(r''' 1068 Source source = addSource(r'''
1066 class A { 1069 class A {
1067 bool get g => true; 1070 bool get g => true;
1068 } 1071 }
1069 A f(var p) { 1072 A f(var p) {
1070 if ((p as A).g) { 1073 if ((p as A).g) {
1071 return p; 1074 return p;
1072 } else { 1075 } else {
1073 return null; 1076 return null;
1074 } 1077 }
1075 }'''); 1078 }''');
1076 LibraryElement library = resolve2(source); 1079 LibraryElement library = resolve2(source);
1077 assertNoErrors(source); 1080 await assertNoErrors(source);
1078 verify([source]); 1081 verify([source]);
1079 CompilationUnit unit = resolveCompilationUnit(source, library); 1082 CompilationUnit unit = resolveCompilationUnit(source, library);
1080 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; 1083 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration;
1081 InterfaceType typeA = 1084 InterfaceType typeA =
1082 resolutionMap.elementDeclaredByClassDeclaration(classA).type; 1085 resolutionMap.elementDeclaredByClassDeclaration(classA).type;
1083 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; 1086 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration;
1084 BlockFunctionBody body = 1087 BlockFunctionBody body =
1085 function.functionExpression.body as BlockFunctionBody; 1088 function.functionExpression.body as BlockFunctionBody;
1086 IfStatement ifStatement = body.block.statements[0] as IfStatement; 1089 IfStatement ifStatement = body.block.statements[0] as IfStatement;
1087 ReturnStatement statement = 1090 ReturnStatement statement =
1088 (ifStatement.thenStatement as Block).statements[0] as ReturnStatement; 1091 (ifStatement.thenStatement as Block).statements[0] as ReturnStatement;
1089 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; 1092 SimpleIdentifier variableName = statement.expression as SimpleIdentifier;
1090 expect(variableName.propagatedType, same(typeA)); 1093 expect(variableName.propagatedType, same(typeA));
1091 } 1094 }
1092 1095
1093 void test_assert() { 1096 test_assert() async {
1094 Source source = addSource(r''' 1097 Source source = addSource(r'''
1095 class A {} 1098 class A {}
1096 A f(var p) { 1099 A f(var p) {
1097 assert (p is A); 1100 assert (p is A);
1098 return p; 1101 return p;
1099 }'''); 1102 }''');
1100 LibraryElement library = resolve2(source); 1103 LibraryElement library = resolve2(source);
1101 assertNoErrors(source); 1104 await assertNoErrors(source);
1102 verify([source]); 1105 verify([source]);
1103 CompilationUnit unit = resolveCompilationUnit(source, library); 1106 CompilationUnit unit = resolveCompilationUnit(source, library);
1104 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; 1107 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration;
1105 InterfaceType typeA = 1108 InterfaceType typeA =
1106 resolutionMap.elementDeclaredByClassDeclaration(classA).type; 1109 resolutionMap.elementDeclaredByClassDeclaration(classA).type;
1107 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; 1110 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration;
1108 BlockFunctionBody body = 1111 BlockFunctionBody body =
1109 function.functionExpression.body as BlockFunctionBody; 1112 function.functionExpression.body as BlockFunctionBody;
1110 ReturnStatement statement = body.block.statements[1] as ReturnStatement; 1113 ReturnStatement statement = body.block.statements[1] as ReturnStatement;
1111 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; 1114 SimpleIdentifier variableName = statement.expression as SimpleIdentifier;
1112 expect(variableName.propagatedType, same(typeA)); 1115 expect(variableName.propagatedType, same(typeA));
1113 } 1116 }
1114 1117
1115 void test_assignment() { 1118 test_assignment() async {
1116 Source source = addSource(r''' 1119 Source source = addSource(r'''
1117 f() { 1120 f() {
1118 var v; 1121 var v;
1119 v = 0; 1122 v = 0;
1120 return v; 1123 return v;
1121 }'''); 1124 }''');
1122 LibraryElement library = resolve2(source); 1125 LibraryElement library = resolve2(source);
1123 assertNoErrors(source); 1126 await assertNoErrors(source);
1124 verify([source]); 1127 verify([source]);
1125 CompilationUnit unit = resolveCompilationUnit(source, library); 1128 CompilationUnit unit = resolveCompilationUnit(source, library);
1126 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; 1129 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration;
1127 BlockFunctionBody body = 1130 BlockFunctionBody body =
1128 function.functionExpression.body as BlockFunctionBody; 1131 function.functionExpression.body as BlockFunctionBody;
1129 ReturnStatement statement = body.block.statements[2] as ReturnStatement; 1132 ReturnStatement statement = body.block.statements[2] as ReturnStatement;
1130 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; 1133 SimpleIdentifier variableName = statement.expression as SimpleIdentifier;
1131 expect(variableName.propagatedType, same(typeProvider.intType)); 1134 expect(variableName.propagatedType, same(typeProvider.intType));
1132 } 1135 }
1133 1136
1134 void test_assignment_afterInitializer() { 1137 test_assignment_afterInitializer() async {
1135 Source source = addSource(r''' 1138 Source source = addSource(r'''
1136 f() { 1139 f() {
1137 var v = 0; 1140 var v = 0;
1138 v = 1.0; 1141 v = 1.0;
1139 return v; 1142 return v;
1140 }'''); 1143 }''');
1141 LibraryElement library = resolve2(source); 1144 LibraryElement library = resolve2(source);
1142 assertNoErrors(source); 1145 await assertNoErrors(source);
1143 verify([source]); 1146 verify([source]);
1144 CompilationUnit unit = resolveCompilationUnit(source, library); 1147 CompilationUnit unit = resolveCompilationUnit(source, library);
1145 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; 1148 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration;
1146 BlockFunctionBody body = 1149 BlockFunctionBody body =
1147 function.functionExpression.body as BlockFunctionBody; 1150 function.functionExpression.body as BlockFunctionBody;
1148 ReturnStatement statement = body.block.statements[2] as ReturnStatement; 1151 ReturnStatement statement = body.block.statements[2] as ReturnStatement;
1149 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; 1152 SimpleIdentifier variableName = statement.expression as SimpleIdentifier;
1150 expect(variableName.propagatedType, same(typeProvider.doubleType)); 1153 expect(variableName.propagatedType, same(typeProvider.doubleType));
1151 } 1154 }
1152 1155
1153 void test_assignment_null() { 1156 test_assignment_null() async {
1154 String code = r''' 1157 String code = r'''
1155 main() { 1158 main() {
1156 int v; // declare 1159 int v; // declare
1157 v = null; 1160 v = null;
1158 return v; // return 1161 return v; // return
1159 }'''; 1162 }''';
1160 CompilationUnit unit; 1163 CompilationUnit unit;
1161 { 1164 {
1162 Source source = addSource(code); 1165 Source source = addSource(code);
1163 LibraryElement library = resolve2(source); 1166 LibraryElement library = resolve2(source);
1164 assertNoErrors(source); 1167 await assertNoErrors(source);
1165 verify([source]); 1168 verify([source]);
1166 unit = resolveCompilationUnit(source, library); 1169 unit = resolveCompilationUnit(source, library);
1167 } 1170 }
1168 { 1171 {
1169 SimpleIdentifier identifier = EngineTestCase.findNode( 1172 SimpleIdentifier identifier = EngineTestCase.findNode(
1170 unit, code, "v; // declare", (node) => node is SimpleIdentifier); 1173 unit, code, "v; // declare", (node) => node is SimpleIdentifier);
1171 expect(identifier.staticType, same(typeProvider.intType)); 1174 expect(identifier.staticType, same(typeProvider.intType));
1172 expect(identifier.propagatedType, same(null)); 1175 expect(identifier.propagatedType, same(null));
1173 } 1176 }
1174 { 1177 {
1175 SimpleIdentifier identifier = EngineTestCase.findNode( 1178 SimpleIdentifier identifier = EngineTestCase.findNode(
1176 unit, code, "v = null;", (node) => node is SimpleIdentifier); 1179 unit, code, "v = null;", (node) => node is SimpleIdentifier);
1177 expect(identifier.staticType, same(typeProvider.intType)); 1180 expect(identifier.staticType, same(typeProvider.intType));
1178 expect(identifier.propagatedType, same(null)); 1181 expect(identifier.propagatedType, same(null));
1179 } 1182 }
1180 { 1183 {
1181 SimpleIdentifier identifier = EngineTestCase.findNode( 1184 SimpleIdentifier identifier = EngineTestCase.findNode(
1182 unit, code, "v; // return", (node) => node is SimpleIdentifier); 1185 unit, code, "v; // return", (node) => node is SimpleIdentifier);
1183 expect(identifier.staticType, same(typeProvider.intType)); 1186 expect(identifier.staticType, same(typeProvider.intType));
1184 expect(identifier.propagatedType, same(null)); 1187 expect(identifier.propagatedType, same(null));
1185 } 1188 }
1186 } 1189 }
1187 1190
1188 void test_CanvasElement_getContext() { 1191 test_CanvasElement_getContext() async {
1189 String code = r''' 1192 String code = r'''
1190 import 'dart:html'; 1193 import 'dart:html';
1191 main(CanvasElement canvas) { 1194 main(CanvasElement canvas) {
1192 var context = canvas.getContext('2d'); 1195 var context = canvas.getContext('2d');
1193 }'''; 1196 }''';
1194 Source source = addSource(code); 1197 Source source = addSource(code);
1195 LibraryElement library = resolve2(source); 1198 LibraryElement library = resolve2(source);
1196 assertNoErrors(source); 1199 await assertNoErrors(source);
1197 verify([source]); 1200 verify([source]);
1198 CompilationUnit unit = resolveCompilationUnit(source, library); 1201 CompilationUnit unit = resolveCompilationUnit(source, library);
1199 SimpleIdentifier identifier = EngineTestCase.findNode( 1202 SimpleIdentifier identifier = EngineTestCase.findNode(
1200 unit, code, "context", (node) => node is SimpleIdentifier); 1203 unit, code, "context", (node) => node is SimpleIdentifier);
1201 expect(resolutionMap.propagatedTypeForExpression(identifier).name, 1204 expect(resolutionMap.propagatedTypeForExpression(identifier).name,
1202 "CanvasRenderingContext2D"); 1205 "CanvasRenderingContext2D");
1203 } 1206 }
1204 1207
1205 void test_forEach() { 1208 test_forEach() async {
1206 String code = r''' 1209 String code = r'''
1207 main() { 1210 main() {
1208 var list = <String> []; 1211 var list = <String> [];
1209 for (var e in list) { 1212 for (var e in list) {
1210 e; 1213 e;
1211 } 1214 }
1212 }'''; 1215 }''';
1213 Source source = addSource(code); 1216 Source source = addSource(code);
1214 LibraryElement library = resolve2(source); 1217 LibraryElement library = resolve2(source);
1215 assertNoErrors(source); 1218 await assertNoErrors(source);
1216 verify([source]); 1219 verify([source]);
1217 CompilationUnit unit = resolveCompilationUnit(source, library); 1220 CompilationUnit unit = resolveCompilationUnit(source, library);
1218 InterfaceType stringType = typeProvider.stringType; 1221 InterfaceType stringType = typeProvider.stringType;
1219 // in the declaration 1222 // in the declaration
1220 { 1223 {
1221 SimpleIdentifier identifier = EngineTestCase.findNode( 1224 SimpleIdentifier identifier = EngineTestCase.findNode(
1222 unit, code, "e in", (node) => node is SimpleIdentifier); 1225 unit, code, "e in", (node) => node is SimpleIdentifier);
1223 expect(identifier.propagatedType, same(stringType)); 1226 expect(identifier.propagatedType, same(stringType));
1224 } 1227 }
1225 // in the loop body 1228 // in the loop body
1226 { 1229 {
1227 SimpleIdentifier identifier = EngineTestCase.findNode( 1230 SimpleIdentifier identifier = EngineTestCase.findNode(
1228 unit, code, "e;", (node) => node is SimpleIdentifier); 1231 unit, code, "e;", (node) => node is SimpleIdentifier);
1229 expect(identifier.propagatedType, same(stringType)); 1232 expect(identifier.propagatedType, same(stringType));
1230 } 1233 }
1231 } 1234 }
1232 1235
1233 void test_forEach_async() { 1236 test_forEach_async() async {
1234 String code = r''' 1237 String code = r'''
1235 import 'dart:async'; 1238 import 'dart:async';
1236 f(Stream<String> stream) async { 1239 f(Stream<String> stream) async {
1237 await for (var e in stream) { 1240 await for (var e in stream) {
1238 e; 1241 e;
1239 } 1242 }
1240 }'''; 1243 }''';
1241 Source source = addSource(code); 1244 Source source = addSource(code);
1242 LibraryElement library = resolve2(source); 1245 LibraryElement library = resolve2(source);
1243 assertNoErrors(source); 1246 await assertNoErrors(source);
1244 verify([source]); 1247 verify([source]);
1245 CompilationUnit unit = resolveCompilationUnit(source, library); 1248 CompilationUnit unit = resolveCompilationUnit(source, library);
1246 InterfaceType stringType = typeProvider.stringType; 1249 InterfaceType stringType = typeProvider.stringType;
1247 // in the declaration 1250 // in the declaration
1248 { 1251 {
1249 SimpleIdentifier identifier = EngineTestCase.findNode( 1252 SimpleIdentifier identifier = EngineTestCase.findNode(
1250 unit, code, "e in", (node) => node is SimpleIdentifier); 1253 unit, code, "e in", (node) => node is SimpleIdentifier);
1251 expect(identifier.propagatedType, same(stringType)); 1254 expect(identifier.propagatedType, same(stringType));
1252 } 1255 }
1253 // in the loop body 1256 // in the loop body
1254 { 1257 {
1255 SimpleIdentifier identifier = EngineTestCase.findNode( 1258 SimpleIdentifier identifier = EngineTestCase.findNode(
1256 unit, code, "e;", (node) => node is SimpleIdentifier); 1259 unit, code, "e;", (node) => node is SimpleIdentifier);
1257 expect(identifier.propagatedType, same(stringType)); 1260 expect(identifier.propagatedType, same(stringType));
1258 } 1261 }
1259 } 1262 }
1260 1263
1261 void test_forEach_async_inheritedStream() { 1264 test_forEach_async_inheritedStream() async {
1262 // From https://github.com/dart-lang/sdk/issues/24191, this ensures that 1265 // From https://github.com/dart-lang/sdk/issues/24191, this ensures that
1263 // `await for` works for types where the generic parameter doesn't 1266 // `await for` works for types where the generic parameter doesn't
1264 // correspond to the type of the Stream's data. 1267 // correspond to the type of the Stream's data.
1265 String code = r''' 1268 String code = r'''
1266 import 'dart:async'; 1269 import 'dart:async';
1267 abstract class MyCustomStream<T> implements Stream<List<T>> {} 1270 abstract class MyCustomStream<T> implements Stream<List<T>> {}
1268 f(MyCustomStream<String> stream) async { 1271 f(MyCustomStream<String> stream) async {
1269 await for (var e in stream) { 1272 await for (var e in stream) {
1270 e; 1273 e;
1271 } 1274 }
1272 }'''; 1275 }''';
1273 Source source = addSource(code); 1276 Source source = addSource(code);
1274 LibraryElement library = resolve2(source); 1277 LibraryElement library = resolve2(source);
1275 assertNoErrors(source); 1278 await assertNoErrors(source);
1276 verify([source]); 1279 verify([source]);
1277 CompilationUnit unit = resolveCompilationUnit(source, library); 1280 CompilationUnit unit = resolveCompilationUnit(source, library);
1278 InterfaceType listOfStringType = 1281 InterfaceType listOfStringType =
1279 typeProvider.listType.instantiate([typeProvider.stringType]); 1282 typeProvider.listType.instantiate([typeProvider.stringType]);
1280 // in the declaration 1283 // in the declaration
1281 { 1284 {
1282 SimpleIdentifier identifier = EngineTestCase.findNode( 1285 SimpleIdentifier identifier = EngineTestCase.findNode(
1283 unit, code, "e in", (node) => node is SimpleIdentifier); 1286 unit, code, "e in", (node) => node is SimpleIdentifier);
1284 expect(identifier.propagatedType, equals(listOfStringType)); 1287 expect(identifier.propagatedType, equals(listOfStringType));
1285 } 1288 }
1286 // in the loop body 1289 // in the loop body
1287 { 1290 {
1288 SimpleIdentifier identifier = EngineTestCase.findNode( 1291 SimpleIdentifier identifier = EngineTestCase.findNode(
1289 unit, code, "e;", (node) => node is SimpleIdentifier); 1292 unit, code, "e;", (node) => node is SimpleIdentifier);
1290 expect(identifier.propagatedType, equals(listOfStringType)); 1293 expect(identifier.propagatedType, equals(listOfStringType));
1291 } 1294 }
1292 } 1295 }
1293 1296
1294 void test_functionExpression_asInvocationArgument() { 1297 test_functionExpression_asInvocationArgument() async {
1295 String code = r''' 1298 String code = r'''
1296 class MyMap<K, V> { 1299 class MyMap<K, V> {
1297 forEach(f(K key, V value)) {} 1300 forEach(f(K key, V value)) {}
1298 } 1301 }
1299 f(MyMap<int, String> m) { 1302 f(MyMap<int, String> m) {
1300 m.forEach((k, v) { 1303 m.forEach((k, v) {
1301 k; 1304 k;
1302 v; 1305 v;
1303 }); 1306 });
1304 }'''; 1307 }''';
1305 Source source = addSource(code); 1308 Source source = addSource(code);
1306 LibraryElement library = resolve2(source); 1309 LibraryElement library = resolve2(source);
1307 assertNoErrors(source); 1310 await assertNoErrors(source);
1308 verify([source]); 1311 verify([source]);
1309 CompilationUnit unit = resolveCompilationUnit(source, library); 1312 CompilationUnit unit = resolveCompilationUnit(source, library);
1310 // k 1313 // k
1311 DartType intType = typeProvider.intType; 1314 DartType intType = typeProvider.intType;
1312 FormalParameter kParameter = EngineTestCase.findNode( 1315 FormalParameter kParameter = EngineTestCase.findNode(
1313 unit, code, "k, ", (node) => node is SimpleFormalParameter); 1316 unit, code, "k, ", (node) => node is SimpleFormalParameter);
1314 expect(kParameter.identifier.propagatedType, same(intType)); 1317 expect(kParameter.identifier.propagatedType, same(intType));
1315 SimpleIdentifier kIdentifier = EngineTestCase.findNode( 1318 SimpleIdentifier kIdentifier = EngineTestCase.findNode(
1316 unit, code, "k;", (node) => node is SimpleIdentifier); 1319 unit, code, "k;", (node) => node is SimpleIdentifier);
1317 expect(kIdentifier.propagatedType, same(intType)); 1320 expect(kIdentifier.propagatedType, same(intType));
1318 expect(kIdentifier.staticType, same(typeProvider.dynamicType)); 1321 expect(kIdentifier.staticType, same(typeProvider.dynamicType));
1319 // v 1322 // v
1320 DartType stringType = typeProvider.stringType; 1323 DartType stringType = typeProvider.stringType;
1321 FormalParameter vParameter = EngineTestCase.findNode( 1324 FormalParameter vParameter = EngineTestCase.findNode(
1322 unit, code, "v)", (node) => node is SimpleFormalParameter); 1325 unit, code, "v)", (node) => node is SimpleFormalParameter);
1323 expect(vParameter.identifier.propagatedType, same(stringType)); 1326 expect(vParameter.identifier.propagatedType, same(stringType));
1324 SimpleIdentifier vIdentifier = EngineTestCase.findNode( 1327 SimpleIdentifier vIdentifier = EngineTestCase.findNode(
1325 unit, code, "v;", (node) => node is SimpleIdentifier); 1328 unit, code, "v;", (node) => node is SimpleIdentifier);
1326 expect(vIdentifier.propagatedType, same(stringType)); 1329 expect(vIdentifier.propagatedType, same(stringType));
1327 expect(vIdentifier.staticType, same(typeProvider.dynamicType)); 1330 expect(vIdentifier.staticType, same(typeProvider.dynamicType));
1328 } 1331 }
1329 1332
1330 void test_functionExpression_asInvocationArgument_fromInferredInvocation() { 1333 test_functionExpression_asInvocationArgument_fromInferredInvocation() async {
1331 String code = r''' 1334 String code = r'''
1332 class MyMap<K, V> { 1335 class MyMap<K, V> {
1333 forEach(f(K key, V value)) {} 1336 forEach(f(K key, V value)) {}
1334 } 1337 }
1335 f(MyMap<int, String> m) { 1338 f(MyMap<int, String> m) {
1336 var m2 = m; 1339 var m2 = m;
1337 m2.forEach((k, v) {}); 1340 m2.forEach((k, v) {});
1338 }'''; 1341 }''';
1339 Source source = addSource(code); 1342 Source source = addSource(code);
1340 LibraryElement library = resolve2(source); 1343 LibraryElement library = resolve2(source);
1341 assertNoErrors(source); 1344 await assertNoErrors(source);
1342 verify([source]); 1345 verify([source]);
1343 CompilationUnit unit = resolveCompilationUnit(source, library); 1346 CompilationUnit unit = resolveCompilationUnit(source, library);
1344 // k 1347 // k
1345 DartType intType = typeProvider.intType; 1348 DartType intType = typeProvider.intType;
1346 FormalParameter kParameter = EngineTestCase.findNode( 1349 FormalParameter kParameter = EngineTestCase.findNode(
1347 unit, code, "k, ", (node) => node is SimpleFormalParameter); 1350 unit, code, "k, ", (node) => node is SimpleFormalParameter);
1348 expect(kParameter.identifier.propagatedType, same(intType)); 1351 expect(kParameter.identifier.propagatedType, same(intType));
1349 // v 1352 // v
1350 DartType stringType = typeProvider.stringType; 1353 DartType stringType = typeProvider.stringType;
1351 FormalParameter vParameter = EngineTestCase.findNode( 1354 FormalParameter vParameter = EngineTestCase.findNode(
1352 unit, code, "v)", (node) => node is SimpleFormalParameter); 1355 unit, code, "v)", (node) => node is SimpleFormalParameter);
1353 expect(vParameter.identifier.propagatedType, same(stringType)); 1356 expect(vParameter.identifier.propagatedType, same(stringType));
1354 } 1357 }
1355 1358
1356 void 1359 test_functionExpression_asInvocationArgument_functionExpressionInvocation() as ync {
1357 test_functionExpression_asInvocationArgument_functionExpressionInvocation( ) {
1358 String code = r''' 1360 String code = r'''
1359 main() { 1361 main() {
1360 (f(String value)) {} ((v) { 1362 (f(String value)) {} ((v) {
1361 v; 1363 v;
1362 }); 1364 });
1363 }'''; 1365 }''';
1364 Source source = addSource(code); 1366 Source source = addSource(code);
1365 LibraryElement library = resolve2(source); 1367 LibraryElement library = resolve2(source);
1366 assertNoErrors(source); 1368 await assertNoErrors(source);
1367 verify([source]); 1369 verify([source]);
1368 CompilationUnit unit = resolveCompilationUnit(source, library); 1370 CompilationUnit unit = resolveCompilationUnit(source, library);
1369 // v 1371 // v
1370 DartType dynamicType = typeProvider.dynamicType; 1372 DartType dynamicType = typeProvider.dynamicType;
1371 DartType stringType = typeProvider.stringType; 1373 DartType stringType = typeProvider.stringType;
1372 FormalParameter vParameter = EngineTestCase.findNode( 1374 FormalParameter vParameter = EngineTestCase.findNode(
1373 unit, code, "v)", (node) => node is FormalParameter); 1375 unit, code, "v)", (node) => node is FormalParameter);
1374 expect(vParameter.identifier.propagatedType, same(stringType)); 1376 expect(vParameter.identifier.propagatedType, same(stringType));
1375 expect(vParameter.identifier.staticType, same(dynamicType)); 1377 expect(vParameter.identifier.staticType, same(dynamicType));
1376 SimpleIdentifier vIdentifier = EngineTestCase.findNode( 1378 SimpleIdentifier vIdentifier = EngineTestCase.findNode(
1377 unit, code, "v;", (node) => node is SimpleIdentifier); 1379 unit, code, "v;", (node) => node is SimpleIdentifier);
1378 expect(vIdentifier.propagatedType, same(stringType)); 1380 expect(vIdentifier.propagatedType, same(stringType));
1379 expect(vIdentifier.staticType, same(dynamicType)); 1381 expect(vIdentifier.staticType, same(dynamicType));
1380 } 1382 }
1381 1383
1382 void test_functionExpression_asInvocationArgument_keepIfLessSpecific() { 1384 test_functionExpression_asInvocationArgument_keepIfLessSpecific() async {
1383 String code = r''' 1385 String code = r'''
1384 class MyList { 1386 class MyList {
1385 forEach(f(Object value)) {} 1387 forEach(f(Object value)) {}
1386 } 1388 }
1387 f(MyList list) { 1389 f(MyList list) {
1388 list.forEach((int v) { 1390 list.forEach((int v) {
1389 v; 1391 v;
1390 }); 1392 });
1391 }'''; 1393 }''';
1392 Source source = addSource(code); 1394 Source source = addSource(code);
1393 LibraryElement library = resolve2(source); 1395 LibraryElement library = resolve2(source);
1394 assertNoErrors(source); 1396 await assertNoErrors(source);
1395 verify([source]); 1397 verify([source]);
1396 CompilationUnit unit = resolveCompilationUnit(source, library); 1398 CompilationUnit unit = resolveCompilationUnit(source, library);
1397 // v 1399 // v
1398 DartType intType = typeProvider.intType; 1400 DartType intType = typeProvider.intType;
1399 FormalParameter vParameter = EngineTestCase.findNode( 1401 FormalParameter vParameter = EngineTestCase.findNode(
1400 unit, code, "v)", (node) => node is SimpleFormalParameter); 1402 unit, code, "v)", (node) => node is SimpleFormalParameter);
1401 expect(vParameter.identifier.propagatedType, same(null)); 1403 expect(vParameter.identifier.propagatedType, same(null));
1402 expect(vParameter.identifier.staticType, same(intType)); 1404 expect(vParameter.identifier.staticType, same(intType));
1403 SimpleIdentifier vIdentifier = EngineTestCase.findNode( 1405 SimpleIdentifier vIdentifier = EngineTestCase.findNode(
1404 unit, code, "v;", (node) => node is SimpleIdentifier); 1406 unit, code, "v;", (node) => node is SimpleIdentifier);
1405 expect(vIdentifier.staticType, same(intType)); 1407 expect(vIdentifier.staticType, same(intType));
1406 expect(vIdentifier.propagatedType, same(null)); 1408 expect(vIdentifier.propagatedType, same(null));
1407 } 1409 }
1408 1410
1409 void test_functionExpression_asInvocationArgument_notSubtypeOfStaticType() { 1411 test_functionExpression_asInvocationArgument_notSubtypeOfStaticType() async {
1410 String code = r''' 1412 String code = r'''
1411 class A { 1413 class A {
1412 m(void f(int i)) {} 1414 m(void f(int i)) {}
1413 } 1415 }
1414 x() { 1416 x() {
1415 A a = new A(); 1417 A a = new A();
1416 a.m(() => 0); 1418 a.m(() => 0);
1417 }'''; 1419 }''';
1418 Source source = addSource(code); 1420 Source source = addSource(code);
1419 LibraryElement library = resolve2(source); 1421 LibraryElement library = resolve2(source);
1420 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); 1422 await assertErrors(
1423 source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]);
1421 verify([source]); 1424 verify([source]);
1422 CompilationUnit unit = resolveCompilationUnit(source, library); 1425 CompilationUnit unit = resolveCompilationUnit(source, library);
1423 // () => 0 1426 // () => 0
1424 FunctionExpression functionExpression = EngineTestCase.findNode( 1427 FunctionExpression functionExpression = EngineTestCase.findNode(
1425 unit, code, "() => 0)", (node) => node is FunctionExpression); 1428 unit, code, "() => 0)", (node) => node is FunctionExpression);
1426 expect((functionExpression.staticType as FunctionType).parameters.length, 1429 expect((functionExpression.staticType as FunctionType).parameters.length,
1427 same(0)); 1430 same(0));
1428 expect(functionExpression.propagatedType, same(null)); 1431 expect(functionExpression.propagatedType, same(null));
1429 } 1432 }
1430 1433
1431 void test_functionExpression_asInvocationArgument_replaceIfMoreSpecific() { 1434 test_functionExpression_asInvocationArgument_replaceIfMoreSpecific() async {
1432 String code = r''' 1435 String code = r'''
1433 class MyList<E> { 1436 class MyList<E> {
1434 forEach(f(E value)) {} 1437 forEach(f(E value)) {}
1435 } 1438 }
1436 f(MyList<String> list) { 1439 f(MyList<String> list) {
1437 list.forEach((Object v) { 1440 list.forEach((Object v) {
1438 v; 1441 v;
1439 }); 1442 });
1440 }'''; 1443 }''';
1441 Source source = addSource(code); 1444 Source source = addSource(code);
1442 LibraryElement library = resolve2(source); 1445 LibraryElement library = resolve2(source);
1443 assertNoErrors(source); 1446 await assertNoErrors(source);
1444 verify([source]); 1447 verify([source]);
1445 CompilationUnit unit = resolveCompilationUnit(source, library); 1448 CompilationUnit unit = resolveCompilationUnit(source, library);
1446 // v 1449 // v
1447 DartType stringType = typeProvider.stringType; 1450 DartType stringType = typeProvider.stringType;
1448 FormalParameter vParameter = EngineTestCase.findNode( 1451 FormalParameter vParameter = EngineTestCase.findNode(
1449 unit, code, "v)", (node) => node is SimpleFormalParameter); 1452 unit, code, "v)", (node) => node is SimpleFormalParameter);
1450 expect(vParameter.identifier.propagatedType, same(stringType)); 1453 expect(vParameter.identifier.propagatedType, same(stringType));
1451 expect(vParameter.identifier.staticType, same(typeProvider.objectType)); 1454 expect(vParameter.identifier.staticType, same(typeProvider.objectType));
1452 SimpleIdentifier vIdentifier = EngineTestCase.findNode( 1455 SimpleIdentifier vIdentifier = EngineTestCase.findNode(
1453 unit, code, "v;", (node) => node is SimpleIdentifier); 1456 unit, code, "v;", (node) => node is SimpleIdentifier);
1454 expect(vIdentifier.propagatedType, same(stringType)); 1457 expect(vIdentifier.propagatedType, same(stringType));
1455 } 1458 }
1456 1459
1457 void test_Future_then() { 1460 test_Future_then() async {
1458 String code = r''' 1461 String code = r'''
1459 import 'dart:async'; 1462 import 'dart:async';
1460 main(Future<int> firstFuture) { 1463 main(Future<int> firstFuture) {
1461 firstFuture.then((p1) { 1464 firstFuture.then((p1) {
1462 return 1.0; 1465 return 1.0;
1463 }).then((p2) { 1466 }).then((p2) {
1464 return new Future<String>.value('str'); 1467 return new Future<String>.value('str');
1465 }).then((p3) { 1468 }).then((p3) {
1466 }); 1469 });
1467 }'''; 1470 }''';
1468 Source source = addSource(code); 1471 Source source = addSource(code);
1469 LibraryElement library = resolve2(source); 1472 LibraryElement library = resolve2(source);
1470 assertNoErrors(source); 1473 await assertNoErrors(source);
1471 verify([source]); 1474 verify([source]);
1472 CompilationUnit unit = resolveCompilationUnit(source, library); 1475 CompilationUnit unit = resolveCompilationUnit(source, library);
1473 // p1 1476 // p1
1474 FormalParameter p1 = EngineTestCase.findNode( 1477 FormalParameter p1 = EngineTestCase.findNode(
1475 unit, code, "p1) {", (node) => node is SimpleFormalParameter); 1478 unit, code, "p1) {", (node) => node is SimpleFormalParameter);
1476 expect(p1.identifier.propagatedType, same(typeProvider.intType)); 1479 expect(p1.identifier.propagatedType, same(typeProvider.intType));
1477 // p2 1480 // p2
1478 FormalParameter p2 = EngineTestCase.findNode( 1481 FormalParameter p2 = EngineTestCase.findNode(
1479 unit, code, "p2) {", (node) => node is SimpleFormalParameter); 1482 unit, code, "p2) {", (node) => node is SimpleFormalParameter);
1480 expect(p2.identifier.propagatedType, same(typeProvider.doubleType)); 1483 expect(p2.identifier.propagatedType, same(typeProvider.doubleType));
1481 // p3 1484 // p3
1482 FormalParameter p3 = EngineTestCase.findNode( 1485 FormalParameter p3 = EngineTestCase.findNode(
1483 unit, code, "p3) {", (node) => node is SimpleFormalParameter); 1486 unit, code, "p3) {", (node) => node is SimpleFormalParameter);
1484 expect(p3.identifier.propagatedType, same(typeProvider.stringType)); 1487 expect(p3.identifier.propagatedType, same(typeProvider.stringType));
1485 } 1488 }
1486 1489
1487 void test_initializer() { 1490 test_initializer() async {
1488 Source source = addSource(r''' 1491 Source source = addSource(r'''
1489 f() { 1492 f() {
1490 var v = 0; 1493 var v = 0;
1491 return v; 1494 return v;
1492 }'''); 1495 }''');
1493 LibraryElement library = resolve2(source); 1496 LibraryElement library = resolve2(source);
1494 assertNoErrors(source); 1497 await assertNoErrors(source);
1495 verify([source]); 1498 verify([source]);
1496 CompilationUnit unit = resolveCompilationUnit(source, library); 1499 CompilationUnit unit = resolveCompilationUnit(source, library);
1497 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; 1500 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration;
1498 BlockFunctionBody body = 1501 BlockFunctionBody body =
1499 function.functionExpression.body as BlockFunctionBody; 1502 function.functionExpression.body as BlockFunctionBody;
1500 NodeList<Statement> statements = body.block.statements; 1503 NodeList<Statement> statements = body.block.statements;
1501 // Type of 'v' in declaration. 1504 // Type of 'v' in declaration.
1502 { 1505 {
1503 VariableDeclarationStatement statement = 1506 VariableDeclarationStatement statement =
1504 statements[0] as VariableDeclarationStatement; 1507 statements[0] as VariableDeclarationStatement;
1505 SimpleIdentifier variableName = statement.variables.variables[0].name; 1508 SimpleIdentifier variableName = statement.variables.variables[0].name;
1506 expect(variableName.staticType, same(typeProvider.dynamicType)); 1509 expect(variableName.staticType, same(typeProvider.dynamicType));
1507 expect(variableName.propagatedType, same(typeProvider.intType)); 1510 expect(variableName.propagatedType, same(typeProvider.intType));
1508 } 1511 }
1509 // Type of 'v' in reference. 1512 // Type of 'v' in reference.
1510 { 1513 {
1511 ReturnStatement statement = statements[1] as ReturnStatement; 1514 ReturnStatement statement = statements[1] as ReturnStatement;
1512 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; 1515 SimpleIdentifier variableName = statement.expression as SimpleIdentifier;
1513 expect(variableName.propagatedType, same(typeProvider.intType)); 1516 expect(variableName.propagatedType, same(typeProvider.intType));
1514 } 1517 }
1515 } 1518 }
1516 1519
1517 void test_initializer_dereference() { 1520 test_initializer_dereference() async {
1518 Source source = addSource(r''' 1521 Source source = addSource(r'''
1519 f() { 1522 f() {
1520 var v = 'String'; 1523 var v = 'String';
1521 v. 1524 v.
1522 }'''); 1525 }''');
1523 LibraryElement library = resolve2(source); 1526 LibraryElement library = resolve2(source);
1524 CompilationUnit unit = resolveCompilationUnit(source, library); 1527 CompilationUnit unit = resolveCompilationUnit(source, library);
1525 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; 1528 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration;
1526 BlockFunctionBody body = 1529 BlockFunctionBody body =
1527 function.functionExpression.body as BlockFunctionBody; 1530 function.functionExpression.body as BlockFunctionBody;
1528 ExpressionStatement statement = 1531 ExpressionStatement statement =
1529 body.block.statements[1] as ExpressionStatement; 1532 body.block.statements[1] as ExpressionStatement;
1530 PrefixedIdentifier invocation = statement.expression as PrefixedIdentifier; 1533 PrefixedIdentifier invocation = statement.expression as PrefixedIdentifier;
1531 SimpleIdentifier variableName = invocation.prefix; 1534 SimpleIdentifier variableName = invocation.prefix;
1532 expect(variableName.propagatedType, same(typeProvider.stringType)); 1535 expect(variableName.propagatedType, same(typeProvider.stringType));
1533 } 1536 }
1534 1537
1535 void test_initializer_hasStaticType() { 1538 test_initializer_hasStaticType() async {
1536 Source source = addSource(r''' 1539 Source source = addSource(r'''
1537 f() { 1540 f() {
1538 int v = 0; 1541 int v = 0;
1539 return v; 1542 return v;
1540 }'''); 1543 }''');
1541 LibraryElement library = resolve2(source); 1544 LibraryElement library = resolve2(source);
1542 assertNoErrors(source); 1545 await assertNoErrors(source);
1543 verify([source]); 1546 verify([source]);
1544 CompilationUnit unit = resolveCompilationUnit(source, library); 1547 CompilationUnit unit = resolveCompilationUnit(source, library);
1545 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; 1548 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration;
1546 BlockFunctionBody body = 1549 BlockFunctionBody body =
1547 function.functionExpression.body as BlockFunctionBody; 1550 function.functionExpression.body as BlockFunctionBody;
1548 NodeList<Statement> statements = body.block.statements; 1551 NodeList<Statement> statements = body.block.statements;
1549 // Type of 'v' in declaration. 1552 // Type of 'v' in declaration.
1550 { 1553 {
1551 VariableDeclarationStatement statement = 1554 VariableDeclarationStatement statement =
1552 statements[0] as VariableDeclarationStatement; 1555 statements[0] as VariableDeclarationStatement;
1553 SimpleIdentifier variableName = statement.variables.variables[0].name; 1556 SimpleIdentifier variableName = statement.variables.variables[0].name;
1554 expect(variableName.staticType, same(typeProvider.intType)); 1557 expect(variableName.staticType, same(typeProvider.intType));
1555 expect(variableName.propagatedType, isNull); 1558 expect(variableName.propagatedType, isNull);
1556 } 1559 }
1557 // Type of 'v' in reference. 1560 // Type of 'v' in reference.
1558 { 1561 {
1559 ReturnStatement statement = statements[1] as ReturnStatement; 1562 ReturnStatement statement = statements[1] as ReturnStatement;
1560 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; 1563 SimpleIdentifier variableName = statement.expression as SimpleIdentifier;
1561 expect(variableName.staticType, same(typeProvider.intType)); 1564 expect(variableName.staticType, same(typeProvider.intType));
1562 expect(variableName.propagatedType, isNull); 1565 expect(variableName.propagatedType, isNull);
1563 } 1566 }
1564 } 1567 }
1565 1568
1566 void test_initializer_hasStaticType_parameterized() { 1569 test_initializer_hasStaticType_parameterized() async {
1567 Source source = addSource(r''' 1570 Source source = addSource(r'''
1568 f() { 1571 f() {
1569 List<int> v = <int>[]; 1572 List<int> v = <int>[];
1570 return v; 1573 return v;
1571 }'''); 1574 }''');
1572 LibraryElement library = resolve2(source); 1575 LibraryElement library = resolve2(source);
1573 assertNoErrors(source); 1576 await assertNoErrors(source);
1574 verify([source]); 1577 verify([source]);
1575 CompilationUnit unit = resolveCompilationUnit(source, library); 1578 CompilationUnit unit = resolveCompilationUnit(source, library);
1576 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; 1579 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration;
1577 BlockFunctionBody body = 1580 BlockFunctionBody body =
1578 function.functionExpression.body as BlockFunctionBody; 1581 function.functionExpression.body as BlockFunctionBody;
1579 NodeList<Statement> statements = body.block.statements; 1582 NodeList<Statement> statements = body.block.statements;
1580 // Type of 'v' in declaration. 1583 // Type of 'v' in declaration.
1581 { 1584 {
1582 VariableDeclarationStatement statement = 1585 VariableDeclarationStatement statement =
1583 statements[0] as VariableDeclarationStatement; 1586 statements[0] as VariableDeclarationStatement;
1584 SimpleIdentifier variableName = statement.variables.variables[0].name; 1587 SimpleIdentifier variableName = statement.variables.variables[0].name;
1585 expect(variableName.staticType, isNotNull); 1588 expect(variableName.staticType, isNotNull);
1586 expect(variableName.propagatedType, isNull); 1589 expect(variableName.propagatedType, isNull);
1587 } 1590 }
1588 // Type of 'v' in reference. 1591 // Type of 'v' in reference.
1589 { 1592 {
1590 ReturnStatement statement = statements[1] as ReturnStatement; 1593 ReturnStatement statement = statements[1] as ReturnStatement;
1591 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; 1594 SimpleIdentifier variableName = statement.expression as SimpleIdentifier;
1592 expect(variableName.staticType, isNotNull); 1595 expect(variableName.staticType, isNotNull);
1593 expect(variableName.propagatedType, isNull); 1596 expect(variableName.propagatedType, isNull);
1594 } 1597 }
1595 } 1598 }
1596 1599
1597 void test_initializer_null() { 1600 test_initializer_null() async {
1598 String code = r''' 1601 String code = r'''
1599 main() { 1602 main() {
1600 int v = null; 1603 int v = null;
1601 return v; // marker 1604 return v; // marker
1602 }'''; 1605 }''';
1603 CompilationUnit unit; 1606 CompilationUnit unit;
1604 { 1607 {
1605 Source source = addSource(code); 1608 Source source = addSource(code);
1606 LibraryElement library = resolve2(source); 1609 LibraryElement library = resolve2(source);
1607 assertNoErrors(source); 1610 await assertNoErrors(source);
1608 verify([source]); 1611 verify([source]);
1609 unit = resolveCompilationUnit(source, library); 1612 unit = resolveCompilationUnit(source, library);
1610 } 1613 }
1611 { 1614 {
1612 SimpleIdentifier identifier = EngineTestCase.findNode( 1615 SimpleIdentifier identifier = EngineTestCase.findNode(
1613 unit, code, "v = null;", (node) => node is SimpleIdentifier); 1616 unit, code, "v = null;", (node) => node is SimpleIdentifier);
1614 expect(identifier.staticType, same(typeProvider.intType)); 1617 expect(identifier.staticType, same(typeProvider.intType));
1615 expect(identifier.propagatedType, same(null)); 1618 expect(identifier.propagatedType, same(null));
1616 } 1619 }
1617 { 1620 {
1618 SimpleIdentifier identifier = EngineTestCase.findNode( 1621 SimpleIdentifier identifier = EngineTestCase.findNode(
1619 unit, code, "v; // marker", (node) => node is SimpleIdentifier); 1622 unit, code, "v; // marker", (node) => node is SimpleIdentifier);
1620 expect(identifier.staticType, same(typeProvider.intType)); 1623 expect(identifier.staticType, same(typeProvider.intType));
1621 expect(identifier.propagatedType, same(null)); 1624 expect(identifier.propagatedType, same(null));
1622 } 1625 }
1623 } 1626 }
1624 1627
1625 void test_invocation_target_prefixed() { 1628 test_invocation_target_prefixed() async {
1626 addNamedSource( 1629 addNamedSource(
1627 '/helper.dart', 1630 '/helper.dart',
1628 ''' 1631 '''
1629 library helper; 1632 library helper;
1630 int max(int x, int y) => 0; 1633 int max(int x, int y) => 0;
1631 '''); 1634 ''');
1632 String code = ''' 1635 String code = '''
1633 import 'helper.dart' as helper; 1636 import 'helper.dart' as helper;
1634 main() { 1637 main() {
1635 helper.max(10, 10); // marker 1638 helper.max(10, 10); // marker
1636 }'''; 1639 }''';
1637 SimpleIdentifier methodName = 1640 SimpleIdentifier methodName =
1638 findMarkedIdentifier(code, "(10, 10); // marker"); 1641 await findMarkedIdentifier(code, "(10, 10); // marker");
1639 MethodInvocation methodInvoke = methodName.parent; 1642 MethodInvocation methodInvoke = methodName.parent;
1640 expect(methodInvoke.methodName.staticElement, isNotNull); 1643 expect(methodInvoke.methodName.staticElement, isNotNull);
1641 expect(methodInvoke.methodName.propagatedElement, isNull); 1644 expect(methodInvoke.methodName.propagatedElement, isNull);
1642 } 1645 }
1643 1646
1644 void test_is_conditional() { 1647 test_is_conditional() async {
1645 Source source = addSource(r''' 1648 Source source = addSource(r'''
1646 class A {} 1649 class A {}
1647 A f(var p) { 1650 A f(var p) {
1648 return (p is A) ? p : null; 1651 return (p is A) ? p : null;
1649 }'''); 1652 }''');
1650 LibraryElement library = resolve2(source); 1653 LibraryElement library = resolve2(source);
1651 assertNoErrors(source); 1654 await assertNoErrors(source);
1652 verify([source]); 1655 verify([source]);
1653 CompilationUnit unit = resolveCompilationUnit(source, library); 1656 CompilationUnit unit = resolveCompilationUnit(source, library);
1654 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; 1657 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration;
1655 InterfaceType typeA = 1658 InterfaceType typeA =
1656 resolutionMap.elementDeclaredByClassDeclaration(classA).type; 1659 resolutionMap.elementDeclaredByClassDeclaration(classA).type;
1657 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; 1660 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration;
1658 BlockFunctionBody body = 1661 BlockFunctionBody body =
1659 function.functionExpression.body as BlockFunctionBody; 1662 function.functionExpression.body as BlockFunctionBody;
1660 ReturnStatement statement = body.block.statements[0] as ReturnStatement; 1663 ReturnStatement statement = body.block.statements[0] as ReturnStatement;
1661 ConditionalExpression conditional = 1664 ConditionalExpression conditional =
1662 statement.expression as ConditionalExpression; 1665 statement.expression as ConditionalExpression;
1663 SimpleIdentifier variableName = 1666 SimpleIdentifier variableName =
1664 conditional.thenExpression as SimpleIdentifier; 1667 conditional.thenExpression as SimpleIdentifier;
1665 expect(variableName.propagatedType, same(typeA)); 1668 expect(variableName.propagatedType, same(typeA));
1666 } 1669 }
1667 1670
1668 void test_is_if() { 1671 test_is_if() async {
1669 Source source = addSource(r''' 1672 Source source = addSource(r'''
1670 class A {} 1673 class A {}
1671 A f(var p) { 1674 A f(var p) {
1672 if (p is A) { 1675 if (p is A) {
1673 return p; 1676 return p;
1674 } else { 1677 } else {
1675 return null; 1678 return null;
1676 } 1679 }
1677 }'''); 1680 }''');
1678 LibraryElement library = resolve2(source); 1681 LibraryElement library = resolve2(source);
1679 assertNoErrors(source); 1682 await assertNoErrors(source);
1680 verify([source]); 1683 verify([source]);
1681 CompilationUnit unit = resolveCompilationUnit(source, library); 1684 CompilationUnit unit = resolveCompilationUnit(source, library);
1682 // prepare A 1685 // prepare A
1683 InterfaceType typeA; 1686 InterfaceType typeA;
1684 { 1687 {
1685 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; 1688 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration;
1686 typeA = resolutionMap.elementDeclaredByClassDeclaration(classA).type; 1689 typeA = resolutionMap.elementDeclaredByClassDeclaration(classA).type;
1687 } 1690 }
1688 // verify "f" 1691 // verify "f"
1689 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; 1692 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration;
1690 BlockFunctionBody body = 1693 BlockFunctionBody body =
1691 function.functionExpression.body as BlockFunctionBody; 1694 function.functionExpression.body as BlockFunctionBody;
1692 IfStatement ifStatement = body.block.statements[0] as IfStatement; 1695 IfStatement ifStatement = body.block.statements[0] as IfStatement;
1693 // "p is A" 1696 // "p is A"
1694 { 1697 {
1695 IsExpression isExpression = ifStatement.condition; 1698 IsExpression isExpression = ifStatement.condition;
1696 SimpleIdentifier variableName = isExpression.expression; 1699 SimpleIdentifier variableName = isExpression.expression;
1697 expect(variableName.propagatedType, isNull); 1700 expect(variableName.propagatedType, isNull);
1698 } 1701 }
1699 // "return p;" 1702 // "return p;"
1700 { 1703 {
1701 ReturnStatement statement = 1704 ReturnStatement statement =
1702 (ifStatement.thenStatement as Block).statements[0] as ReturnStatement; 1705 (ifStatement.thenStatement as Block).statements[0] as ReturnStatement;
1703 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; 1706 SimpleIdentifier variableName = statement.expression as SimpleIdentifier;
1704 expect(variableName.propagatedType, same(typeA)); 1707 expect(variableName.propagatedType, same(typeA));
1705 } 1708 }
1706 } 1709 }
1707 1710
1708 void test_is_if_lessSpecific() { 1711 test_is_if_lessSpecific() async {
1709 Source source = addSource(r''' 1712 Source source = addSource(r'''
1710 class A {} 1713 class A {}
1711 A f(A p) { 1714 A f(A p) {
1712 if (p is String) { 1715 if (p is String) {
1713 return p; 1716 return p;
1714 } else { 1717 } else {
1715 return null; 1718 return null;
1716 } 1719 }
1717 }'''); 1720 }''');
1718 LibraryElement library = resolve2(source); 1721 LibraryElement library = resolve2(source);
1719 assertNoErrors(source); 1722 await assertNoErrors(source);
1720 verify([source]); 1723 verify([source]);
1721 CompilationUnit unit = resolveCompilationUnit(source, library); 1724 CompilationUnit unit = resolveCompilationUnit(source, library);
1722 // ClassDeclaration classA = (ClassDeclaration) unit.getDeclarations().get(0) ; 1725 // ClassDeclaration classA = (ClassDeclaration) unit.getDeclarations().get(0) ;
1723 // InterfaceType typeA = classA.getElement().getType(); 1726 // InterfaceType typeA = classA.getElement().getType();
1724 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; 1727 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration;
1725 BlockFunctionBody body = 1728 BlockFunctionBody body =
1726 function.functionExpression.body as BlockFunctionBody; 1729 function.functionExpression.body as BlockFunctionBody;
1727 IfStatement ifStatement = body.block.statements[0] as IfStatement; 1730 IfStatement ifStatement = body.block.statements[0] as IfStatement;
1728 ReturnStatement statement = 1731 ReturnStatement statement =
1729 (ifStatement.thenStatement as Block).statements[0] as ReturnStatement; 1732 (ifStatement.thenStatement as Block).statements[0] as ReturnStatement;
1730 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; 1733 SimpleIdentifier variableName = statement.expression as SimpleIdentifier;
1731 expect(variableName.propagatedType, same(null)); 1734 expect(variableName.propagatedType, same(null));
1732 } 1735 }
1733 1736
1734 void test_is_if_logicalAnd() { 1737 test_is_if_logicalAnd() async {
1735 Source source = addSource(r''' 1738 Source source = addSource(r'''
1736 class A {} 1739 class A {}
1737 A f(var p) { 1740 A f(var p) {
1738 if (p is A && p != null) { 1741 if (p is A && p != null) {
1739 return p; 1742 return p;
1740 } else { 1743 } else {
1741 return null; 1744 return null;
1742 } 1745 }
1743 }'''); 1746 }''');
1744 LibraryElement library = resolve2(source); 1747 LibraryElement library = resolve2(source);
1745 assertNoErrors(source); 1748 await assertNoErrors(source);
1746 verify([source]); 1749 verify([source]);
1747 CompilationUnit unit = resolveCompilationUnit(source, library); 1750 CompilationUnit unit = resolveCompilationUnit(source, library);
1748 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; 1751 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration;
1749 InterfaceType typeA = 1752 InterfaceType typeA =
1750 resolutionMap.elementDeclaredByClassDeclaration(classA).type; 1753 resolutionMap.elementDeclaredByClassDeclaration(classA).type;
1751 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; 1754 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration;
1752 BlockFunctionBody body = 1755 BlockFunctionBody body =
1753 function.functionExpression.body as BlockFunctionBody; 1756 function.functionExpression.body as BlockFunctionBody;
1754 IfStatement ifStatement = body.block.statements[0] as IfStatement; 1757 IfStatement ifStatement = body.block.statements[0] as IfStatement;
1755 ReturnStatement statement = 1758 ReturnStatement statement =
1756 (ifStatement.thenStatement as Block).statements[0] as ReturnStatement; 1759 (ifStatement.thenStatement as Block).statements[0] as ReturnStatement;
1757 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; 1760 SimpleIdentifier variableName = statement.expression as SimpleIdentifier;
1758 expect(variableName.propagatedType, same(typeA)); 1761 expect(variableName.propagatedType, same(typeA));
1759 } 1762 }
1760 1763
1761 void test_is_postConditional() { 1764 test_is_postConditional() async {
1762 Source source = addSource(r''' 1765 Source source = addSource(r'''
1763 class A {} 1766 class A {}
1764 A f(var p) { 1767 A f(var p) {
1765 A a = (p is A) ? p : throw null; 1768 A a = (p is A) ? p : throw null;
1766 return p; 1769 return p;
1767 }'''); 1770 }''');
1768 LibraryElement library = resolve2(source); 1771 LibraryElement library = resolve2(source);
1769 assertNoErrors(source); 1772 await assertNoErrors(source);
1770 verify([source]); 1773 verify([source]);
1771 CompilationUnit unit = resolveCompilationUnit(source, library); 1774 CompilationUnit unit = resolveCompilationUnit(source, library);
1772 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; 1775 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration;
1773 InterfaceType typeA = 1776 InterfaceType typeA =
1774 resolutionMap.elementDeclaredByClassDeclaration(classA).type; 1777 resolutionMap.elementDeclaredByClassDeclaration(classA).type;
1775 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; 1778 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration;
1776 BlockFunctionBody body = 1779 BlockFunctionBody body =
1777 function.functionExpression.body as BlockFunctionBody; 1780 function.functionExpression.body as BlockFunctionBody;
1778 ReturnStatement statement = body.block.statements[1] as ReturnStatement; 1781 ReturnStatement statement = body.block.statements[1] as ReturnStatement;
1779 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; 1782 SimpleIdentifier variableName = statement.expression as SimpleIdentifier;
1780 expect(variableName.propagatedType, same(typeA)); 1783 expect(variableName.propagatedType, same(typeA));
1781 } 1784 }
1782 1785
1783 void test_is_postIf() { 1786 test_is_postIf() async {
1784 Source source = addSource(r''' 1787 Source source = addSource(r'''
1785 class A {} 1788 class A {}
1786 A f(var p) { 1789 A f(var p) {
1787 if (p is A) { 1790 if (p is A) {
1788 A a = p; 1791 A a = p;
1789 } else { 1792 } else {
1790 return null; 1793 return null;
1791 } 1794 }
1792 return p; 1795 return p;
1793 }'''); 1796 }''');
1794 LibraryElement library = resolve2(source); 1797 LibraryElement library = resolve2(source);
1795 assertNoErrors(source); 1798 await assertNoErrors(source);
1796 verify([source]); 1799 verify([source]);
1797 CompilationUnit unit = resolveCompilationUnit(source, library); 1800 CompilationUnit unit = resolveCompilationUnit(source, library);
1798 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; 1801 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration;
1799 InterfaceType typeA = 1802 InterfaceType typeA =
1800 resolutionMap.elementDeclaredByClassDeclaration(classA).type; 1803 resolutionMap.elementDeclaredByClassDeclaration(classA).type;
1801 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; 1804 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration;
1802 BlockFunctionBody body = 1805 BlockFunctionBody body =
1803 function.functionExpression.body as BlockFunctionBody; 1806 function.functionExpression.body as BlockFunctionBody;
1804 ReturnStatement statement = body.block.statements[1] as ReturnStatement; 1807 ReturnStatement statement = body.block.statements[1] as ReturnStatement;
1805 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; 1808 SimpleIdentifier variableName = statement.expression as SimpleIdentifier;
1806 expect(variableName.propagatedType, same(typeA)); 1809 expect(variableName.propagatedType, same(typeA));
1807 } 1810 }
1808 1811
1809 void test_is_subclass() { 1812 test_is_subclass() async {
1810 Source source = addSource(r''' 1813 Source source = addSource(r'''
1811 class A {} 1814 class A {}
1812 class B extends A { 1815 class B extends A {
1813 B m() => this; 1816 B m() => this;
1814 } 1817 }
1815 A f(A p) { 1818 A f(A p) {
1816 if (p is B) { 1819 if (p is B) {
1817 return p.m(); 1820 return p.m();
1818 } 1821 }
1819 return p; 1822 return p;
1820 }'''); 1823 }''');
1821 LibraryElement library = resolve2(source); 1824 LibraryElement library = resolve2(source);
1822 assertNoErrors(source); 1825 await assertNoErrors(source);
1823 CompilationUnit unit = resolveCompilationUnit(source, library); 1826 CompilationUnit unit = resolveCompilationUnit(source, library);
1824 FunctionDeclaration function = unit.declarations[2] as FunctionDeclaration; 1827 FunctionDeclaration function = unit.declarations[2] as FunctionDeclaration;
1825 BlockFunctionBody body = 1828 BlockFunctionBody body =
1826 function.functionExpression.body as BlockFunctionBody; 1829 function.functionExpression.body as BlockFunctionBody;
1827 IfStatement ifStatement = body.block.statements[0] as IfStatement; 1830 IfStatement ifStatement = body.block.statements[0] as IfStatement;
1828 ReturnStatement statement = 1831 ReturnStatement statement =
1829 (ifStatement.thenStatement as Block).statements[0] as ReturnStatement; 1832 (ifStatement.thenStatement as Block).statements[0] as ReturnStatement;
1830 MethodInvocation invocation = statement.expression as MethodInvocation; 1833 MethodInvocation invocation = statement.expression as MethodInvocation;
1831 expect(invocation.methodName.staticElement, isNotNull); 1834 expect(invocation.methodName.staticElement, isNotNull);
1832 expect(invocation.methodName.propagatedElement, isNull); 1835 expect(invocation.methodName.propagatedElement, isNull);
1833 } 1836 }
1834 1837
1835 void test_is_while() { 1838 test_is_while() async {
1836 Source source = addSource(r''' 1839 Source source = addSource(r'''
1837 class A {} 1840 class A {}
1838 A f(var p) { 1841 A f(var p) {
1839 while (p is A) { 1842 while (p is A) {
1840 return p; 1843 return p;
1841 } 1844 }
1842 return p; 1845 return p;
1843 }'''); 1846 }''');
1844 LibraryElement library = resolve2(source); 1847 LibraryElement library = resolve2(source);
1845 assertNoErrors(source); 1848 await assertNoErrors(source);
1846 verify([source]); 1849 verify([source]);
1847 CompilationUnit unit = resolveCompilationUnit(source, library); 1850 CompilationUnit unit = resolveCompilationUnit(source, library);
1848 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; 1851 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration;
1849 InterfaceType typeA = 1852 InterfaceType typeA =
1850 resolutionMap.elementDeclaredByClassDeclaration(classA).type; 1853 resolutionMap.elementDeclaredByClassDeclaration(classA).type;
1851 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; 1854 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration;
1852 BlockFunctionBody body = 1855 BlockFunctionBody body =
1853 function.functionExpression.body as BlockFunctionBody; 1856 function.functionExpression.body as BlockFunctionBody;
1854 WhileStatement whileStatement = body.block.statements[0] as WhileStatement; 1857 WhileStatement whileStatement = body.block.statements[0] as WhileStatement;
1855 ReturnStatement statement = 1858 ReturnStatement statement =
1856 (whileStatement.body as Block).statements[0] as ReturnStatement; 1859 (whileStatement.body as Block).statements[0] as ReturnStatement;
1857 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; 1860 SimpleIdentifier variableName = statement.expression as SimpleIdentifier;
1858 expect(variableName.propagatedType, same(typeA)); 1861 expect(variableName.propagatedType, same(typeA));
1859 } 1862 }
1860 1863
1861 void test_isNot_conditional() { 1864 test_isNot_conditional() async {
1862 Source source = addSource(r''' 1865 Source source = addSource(r'''
1863 class A {} 1866 class A {}
1864 A f(var p) { 1867 A f(var p) {
1865 return (p is! A) ? null : p; 1868 return (p is! A) ? null : p;
1866 }'''); 1869 }''');
1867 LibraryElement library = resolve2(source); 1870 LibraryElement library = resolve2(source);
1868 assertNoErrors(source); 1871 await assertNoErrors(source);
1869 verify([source]); 1872 verify([source]);
1870 CompilationUnit unit = resolveCompilationUnit(source, library); 1873 CompilationUnit unit = resolveCompilationUnit(source, library);
1871 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; 1874 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration;
1872 InterfaceType typeA = 1875 InterfaceType typeA =
1873 resolutionMap.elementDeclaredByClassDeclaration(classA).type; 1876 resolutionMap.elementDeclaredByClassDeclaration(classA).type;
1874 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; 1877 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration;
1875 BlockFunctionBody body = 1878 BlockFunctionBody body =
1876 function.functionExpression.body as BlockFunctionBody; 1879 function.functionExpression.body as BlockFunctionBody;
1877 ReturnStatement statement = body.block.statements[0] as ReturnStatement; 1880 ReturnStatement statement = body.block.statements[0] as ReturnStatement;
1878 ConditionalExpression conditional = 1881 ConditionalExpression conditional =
1879 statement.expression as ConditionalExpression; 1882 statement.expression as ConditionalExpression;
1880 SimpleIdentifier variableName = 1883 SimpleIdentifier variableName =
1881 conditional.elseExpression as SimpleIdentifier; 1884 conditional.elseExpression as SimpleIdentifier;
1882 expect(variableName.propagatedType, same(typeA)); 1885 expect(variableName.propagatedType, same(typeA));
1883 } 1886 }
1884 1887
1885 void test_isNot_if() { 1888 test_isNot_if() async {
1886 Source source = addSource(r''' 1889 Source source = addSource(r'''
1887 class A {} 1890 class A {}
1888 A f(var p) { 1891 A f(var p) {
1889 if (p is! A) { 1892 if (p is! A) {
1890 return null; 1893 return null;
1891 } else { 1894 } else {
1892 return p; 1895 return p;
1893 } 1896 }
1894 }'''); 1897 }''');
1895 LibraryElement library = resolve2(source); 1898 LibraryElement library = resolve2(source);
1896 assertNoErrors(source); 1899 await assertNoErrors(source);
1897 verify([source]); 1900 verify([source]);
1898 CompilationUnit unit = resolveCompilationUnit(source, library); 1901 CompilationUnit unit = resolveCompilationUnit(source, library);
1899 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; 1902 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration;
1900 InterfaceType typeA = 1903 InterfaceType typeA =
1901 resolutionMap.elementDeclaredByClassDeclaration(classA).type; 1904 resolutionMap.elementDeclaredByClassDeclaration(classA).type;
1902 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; 1905 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration;
1903 BlockFunctionBody body = 1906 BlockFunctionBody body =
1904 function.functionExpression.body as BlockFunctionBody; 1907 function.functionExpression.body as BlockFunctionBody;
1905 IfStatement ifStatement = body.block.statements[0] as IfStatement; 1908 IfStatement ifStatement = body.block.statements[0] as IfStatement;
1906 ReturnStatement statement = 1909 ReturnStatement statement =
1907 (ifStatement.elseStatement as Block).statements[0] as ReturnStatement; 1910 (ifStatement.elseStatement as Block).statements[0] as ReturnStatement;
1908 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; 1911 SimpleIdentifier variableName = statement.expression as SimpleIdentifier;
1909 expect(variableName.propagatedType, same(typeA)); 1912 expect(variableName.propagatedType, same(typeA));
1910 } 1913 }
1911 1914
1912 void test_isNot_if_logicalOr() { 1915 test_isNot_if_logicalOr() async {
1913 Source source = addSource(r''' 1916 Source source = addSource(r'''
1914 class A {} 1917 class A {}
1915 A f(var p) { 1918 A f(var p) {
1916 if (p is! A || null == p) { 1919 if (p is! A || null == p) {
1917 return null; 1920 return null;
1918 } else { 1921 } else {
1919 return p; 1922 return p;
1920 } 1923 }
1921 }'''); 1924 }''');
1922 LibraryElement library = resolve2(source); 1925 LibraryElement library = resolve2(source);
1923 assertNoErrors(source); 1926 await assertNoErrors(source);
1924 CompilationUnit unit = resolveCompilationUnit(source, library); 1927 CompilationUnit unit = resolveCompilationUnit(source, library);
1925 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; 1928 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration;
1926 InterfaceType typeA = 1929 InterfaceType typeA =
1927 resolutionMap.elementDeclaredByClassDeclaration(classA).type; 1930 resolutionMap.elementDeclaredByClassDeclaration(classA).type;
1928 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; 1931 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration;
1929 BlockFunctionBody body = 1932 BlockFunctionBody body =
1930 function.functionExpression.body as BlockFunctionBody; 1933 function.functionExpression.body as BlockFunctionBody;
1931 IfStatement ifStatement = body.block.statements[0] as IfStatement; 1934 IfStatement ifStatement = body.block.statements[0] as IfStatement;
1932 ReturnStatement statement = 1935 ReturnStatement statement =
1933 (ifStatement.elseStatement as Block).statements[0] as ReturnStatement; 1936 (ifStatement.elseStatement as Block).statements[0] as ReturnStatement;
1934 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; 1937 SimpleIdentifier variableName = statement.expression as SimpleIdentifier;
1935 expect(variableName.propagatedType, same(typeA)); 1938 expect(variableName.propagatedType, same(typeA));
1936 } 1939 }
1937 1940
1938 void test_isNot_postConditional() { 1941 test_isNot_postConditional() async {
1939 Source source = addSource(r''' 1942 Source source = addSource(r'''
1940 class A {} 1943 class A {}
1941 A f(var p) { 1944 A f(var p) {
1942 A a = (p is! A) ? throw null : p; 1945 A a = (p is! A) ? throw null : p;
1943 return p; 1946 return p;
1944 }'''); 1947 }''');
1945 LibraryElement library = resolve2(source); 1948 LibraryElement library = resolve2(source);
1946 assertNoErrors(source); 1949 await assertNoErrors(source);
1947 verify([source]); 1950 verify([source]);
1948 CompilationUnit unit = resolveCompilationUnit(source, library); 1951 CompilationUnit unit = resolveCompilationUnit(source, library);
1949 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; 1952 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration;
1950 InterfaceType typeA = 1953 InterfaceType typeA =
1951 resolutionMap.elementDeclaredByClassDeclaration(classA).type; 1954 resolutionMap.elementDeclaredByClassDeclaration(classA).type;
1952 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; 1955 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration;
1953 BlockFunctionBody body = 1956 BlockFunctionBody body =
1954 function.functionExpression.body as BlockFunctionBody; 1957 function.functionExpression.body as BlockFunctionBody;
1955 ReturnStatement statement = body.block.statements[1] as ReturnStatement; 1958 ReturnStatement statement = body.block.statements[1] as ReturnStatement;
1956 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; 1959 SimpleIdentifier variableName = statement.expression as SimpleIdentifier;
1957 expect(variableName.propagatedType, same(typeA)); 1960 expect(variableName.propagatedType, same(typeA));
1958 } 1961 }
1959 1962
1960 void test_isNot_postIf() { 1963 test_isNot_postIf() async {
1961 Source source = addSource(r''' 1964 Source source = addSource(r'''
1962 class A {} 1965 class A {}
1963 A f(var p) { 1966 A f(var p) {
1964 if (p is! A) { 1967 if (p is! A) {
1965 return null; 1968 return null;
1966 } 1969 }
1967 return p; 1970 return p;
1968 }'''); 1971 }''');
1969 LibraryElement library = resolve2(source); 1972 LibraryElement library = resolve2(source);
1970 assertNoErrors(source); 1973 await assertNoErrors(source);
1971 verify([source]); 1974 verify([source]);
1972 CompilationUnit unit = resolveCompilationUnit(source, library); 1975 CompilationUnit unit = resolveCompilationUnit(source, library);
1973 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; 1976 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration;
1974 InterfaceType typeA = 1977 InterfaceType typeA =
1975 resolutionMap.elementDeclaredByClassDeclaration(classA).type; 1978 resolutionMap.elementDeclaredByClassDeclaration(classA).type;
1976 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; 1979 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration;
1977 BlockFunctionBody body = 1980 BlockFunctionBody body =
1978 function.functionExpression.body as BlockFunctionBody; 1981 function.functionExpression.body as BlockFunctionBody;
1979 ReturnStatement statement = body.block.statements[1] as ReturnStatement; 1982 ReturnStatement statement = body.block.statements[1] as ReturnStatement;
1980 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; 1983 SimpleIdentifier variableName = statement.expression as SimpleIdentifier;
1981 expect(variableName.propagatedType, same(typeA)); 1984 expect(variableName.propagatedType, same(typeA));
1982 } 1985 }
1983 1986
1984 void test_issue20904BuggyTypePromotionAtIfJoin_5() { 1987 test_issue20904BuggyTypePromotionAtIfJoin_5() async {
1985 // https://code.google.com/p/dart/issues/detail?id=20904 1988 // https://code.google.com/p/dart/issues/detail?id=20904
1986 // 1989 //
1987 // This is not an example of the 20904 bug, but rather, 1990 // This is not an example of the 20904 bug, but rather,
1988 // an example of something that one obvious fix changes inadvertently: we 1991 // an example of something that one obvious fix changes inadvertently: we
1989 // want to avoid using type information from is-checks when it 1992 // want to avoid using type information from is-checks when it
1990 // loses precision. I can't see how to get a bad hint this way, since 1993 // loses precision. I can't see how to get a bad hint this way, since
1991 // it seems the propagated type is not used to generate hints when a 1994 // it seems the propagated type is not used to generate hints when a
1992 // more precise type would cause no hint. For example, for code like the 1995 // more precise type would cause no hint. For example, for code like the
1993 // following, when the propagated type of [x] is [A] -- as happens for the 1996 // following, when the propagated type of [x] is [A] -- as happens for the
1994 // fix these tests aim to warn against -- there is no warning for 1997 // fix these tests aim to warn against -- there is no warning for
1995 1998
1996 // calling a method defined on [B] but not [A] (there aren't any, but 1999 // calling a method defined on [B] but not [A] (there aren't any, but
1997 // pretend), but there is for calling a method not defined on either. 2000 // pretend), but there is for calling a method not defined on either.
1998 // By not overriding the propagated type via an is-check that loses 2001 // By not overriding the propagated type via an is-check that loses
1999 // precision, we get more precise completion under an is-check. However, 2002 // precision, we get more precise completion under an is-check. However,
2000 // I can only imagine strange code would make use of this feature. 2003 // I can only imagine strange code would make use of this feature.
2001 // 2004 //
2002 // Here the is-check improves precision, so we use it. 2005 // Here the is-check improves precision, so we use it.
2003 String code = r''' 2006 String code = r'''
2004 class A {} 2007 class A {}
2005 class B extends A {} 2008 class B extends A {}
2006 f() { 2009 f() {
2007 var a = new A(); 2010 var a = new A();
2008 var b = new B(); 2011 var b = new B();
2009 b; // B 2012 b; // B
2010 if (a is B) { 2013 if (a is B) {
2011 return a; // marker 2014 return a; // marker
2012 } 2015 }
2013 }'''; 2016 }''';
2014 DartType tB = findMarkedIdentifier(code, "; // B").propagatedType; 2017 DartType tB = (await findMarkedIdentifier(code, "; // B")).propagatedType;
2015 assertTypeOfMarkedExpression(code, null, tB); 2018 await assertTypeOfMarkedExpression(code, null, tB);
2016 } 2019 }
2017 2020
2018 void test_issue20904BuggyTypePromotionAtIfJoin_6() { 2021 test_issue20904BuggyTypePromotionAtIfJoin_6() async {
2019 // https://code.google.com/p/dart/issues/detail?id=20904 2022 // https://code.google.com/p/dart/issues/detail?id=20904
2020 // 2023 //
2021 // The other half of the *_5() test. 2024 // The other half of the *_5() test.
2022 // 2025 //
2023 // Here the is-check loses precision, so we don't use it. 2026 // Here the is-check loses precision, so we don't use it.
2024 String code = r''' 2027 String code = r'''
2025 class A {} 2028 class A {}
2026 class B extends A {} 2029 class B extends A {}
2027 f() { 2030 f() {
2028 var b = new B(); 2031 var b = new B();
2029 b; // B 2032 b; // B
2030 if (b is A) { 2033 if (b is A) {
2031 return b; // marker 2034 return b; // marker
2032 } 2035 }
2033 }'''; 2036 }''';
2034 DartType tB = findMarkedIdentifier(code, "; // B").propagatedType; 2037 DartType tB = (await findMarkedIdentifier(code, "; // B")).propagatedType;
2035 assertTypeOfMarkedExpression(code, null, tB); 2038 await assertTypeOfMarkedExpression(code, null, tB);
2036 } 2039 }
2037 2040
2038 void test_listLiteral_different() { 2041 test_listLiteral_different() async {
2039 Source source = addSource(r''' 2042 Source source = addSource(r'''
2040 f() { 2043 f() {
2041 var v = [0, '1', 2]; 2044 var v = [0, '1', 2];
2042 return v[2]; 2045 return v[2];
2043 }'''); 2046 }''');
2044 LibraryElement library = resolve2(source); 2047 LibraryElement library = resolve2(source);
2045 assertNoErrors(source); 2048 await assertNoErrors(source);
2046 verify([source]); 2049 verify([source]);
2047 CompilationUnit unit = resolveCompilationUnit(source, library); 2050 CompilationUnit unit = resolveCompilationUnit(source, library);
2048 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; 2051 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration;
2049 BlockFunctionBody body = 2052 BlockFunctionBody body =
2050 function.functionExpression.body as BlockFunctionBody; 2053 function.functionExpression.body as BlockFunctionBody;
2051 ReturnStatement statement = body.block.statements[1] as ReturnStatement; 2054 ReturnStatement statement = body.block.statements[1] as ReturnStatement;
2052 IndexExpression indexExpression = statement.expression as IndexExpression; 2055 IndexExpression indexExpression = statement.expression as IndexExpression;
2053 expect(indexExpression.propagatedType, isNull); 2056 expect(indexExpression.propagatedType, isNull);
2054 } 2057 }
2055 2058
2056 void test_listLiteral_same() { 2059 test_listLiteral_same() async {
2057 Source source = addSource(r''' 2060 Source source = addSource(r'''
2058 f() { 2061 f() {
2059 var v = [0, 1, 2]; 2062 var v = [0, 1, 2];
2060 return v[2]; 2063 return v[2];
2061 }'''); 2064 }''');
2062 LibraryElement library = resolve2(source); 2065 LibraryElement library = resolve2(source);
2063 assertNoErrors(source); 2066 await assertNoErrors(source);
2064 verify([source]); 2067 verify([source]);
2065 CompilationUnit unit = resolveCompilationUnit(source, library); 2068 CompilationUnit unit = resolveCompilationUnit(source, library);
2066 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; 2069 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration;
2067 BlockFunctionBody body = 2070 BlockFunctionBody body =
2068 function.functionExpression.body as BlockFunctionBody; 2071 function.functionExpression.body as BlockFunctionBody;
2069 ReturnStatement statement = body.block.statements[1] as ReturnStatement; 2072 ReturnStatement statement = body.block.statements[1] as ReturnStatement;
2070 IndexExpression indexExpression = statement.expression as IndexExpression; 2073 IndexExpression indexExpression = statement.expression as IndexExpression;
2071 expect(indexExpression.propagatedType, isNull); 2074 expect(indexExpression.propagatedType, isNull);
2072 Expression v = indexExpression.target; 2075 Expression v = indexExpression.target;
2073 InterfaceType propagatedType = v.propagatedType as InterfaceType; 2076 InterfaceType propagatedType = v.propagatedType as InterfaceType;
2074 expect(propagatedType.element, same(typeProvider.listType.element)); 2077 expect(propagatedType.element, same(typeProvider.listType.element));
2075 List<DartType> typeArguments = propagatedType.typeArguments; 2078 List<DartType> typeArguments = propagatedType.typeArguments;
2076 expect(typeArguments, hasLength(1)); 2079 expect(typeArguments, hasLength(1));
2077 expect(typeArguments[0], same(typeProvider.dynamicType)); 2080 expect(typeArguments[0], same(typeProvider.dynamicType));
2078 } 2081 }
2079 2082
2080 void test_mapLiteral_different() { 2083 test_mapLiteral_different() async {
2081 Source source = addSource(r''' 2084 Source source = addSource(r'''
2082 f() { 2085 f() {
2083 var v = {'0' : 0, 1 : '1', '2' : 2}; 2086 var v = {'0' : 0, 1 : '1', '2' : 2};
2084 return v; 2087 return v;
2085 }'''); 2088 }''');
2086 LibraryElement library = resolve2(source); 2089 LibraryElement library = resolve2(source);
2087 assertNoErrors(source); 2090 await assertNoErrors(source);
2088 verify([source]); 2091 verify([source]);
2089 CompilationUnit unit = resolveCompilationUnit(source, library); 2092 CompilationUnit unit = resolveCompilationUnit(source, library);
2090 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; 2093 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration;
2091 BlockFunctionBody body = 2094 BlockFunctionBody body =
2092 function.functionExpression.body as BlockFunctionBody; 2095 function.functionExpression.body as BlockFunctionBody;
2093 ReturnStatement statement = body.block.statements[1] as ReturnStatement; 2096 ReturnStatement statement = body.block.statements[1] as ReturnStatement;
2094 SimpleIdentifier identifier = statement.expression as SimpleIdentifier; 2097 SimpleIdentifier identifier = statement.expression as SimpleIdentifier;
2095 InterfaceType propagatedType = identifier.propagatedType as InterfaceType; 2098 InterfaceType propagatedType = identifier.propagatedType as InterfaceType;
2096 expect(propagatedType.element, same(typeProvider.mapType.element)); 2099 expect(propagatedType.element, same(typeProvider.mapType.element));
2097 List<DartType> typeArguments = propagatedType.typeArguments; 2100 List<DartType> typeArguments = propagatedType.typeArguments;
2098 expect(typeArguments, hasLength(2)); 2101 expect(typeArguments, hasLength(2));
2099 expect(typeArguments[0], same(typeProvider.dynamicType)); 2102 expect(typeArguments[0], same(typeProvider.dynamicType));
2100 expect(typeArguments[1], same(typeProvider.dynamicType)); 2103 expect(typeArguments[1], same(typeProvider.dynamicType));
2101 } 2104 }
2102 2105
2103 void test_mapLiteral_same() { 2106 test_mapLiteral_same() async {
2104 Source source = addSource(r''' 2107 Source source = addSource(r'''
2105 f() { 2108 f() {
2106 var v = {'a' : 0, 'b' : 1, 'c' : 2}; 2109 var v = {'a' : 0, 'b' : 1, 'c' : 2};
2107 return v; 2110 return v;
2108 }'''); 2111 }''');
2109 LibraryElement library = resolve2(source); 2112 LibraryElement library = resolve2(source);
2110 assertNoErrors(source); 2113 await assertNoErrors(source);
2111 verify([source]); 2114 verify([source]);
2112 CompilationUnit unit = resolveCompilationUnit(source, library); 2115 CompilationUnit unit = resolveCompilationUnit(source, library);
2113 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; 2116 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration;
2114 BlockFunctionBody body = 2117 BlockFunctionBody body =
2115 function.functionExpression.body as BlockFunctionBody; 2118 function.functionExpression.body as BlockFunctionBody;
2116 ReturnStatement statement = body.block.statements[1] as ReturnStatement; 2119 ReturnStatement statement = body.block.statements[1] as ReturnStatement;
2117 SimpleIdentifier identifier = statement.expression as SimpleIdentifier; 2120 SimpleIdentifier identifier = statement.expression as SimpleIdentifier;
2118 InterfaceType propagatedType = identifier.propagatedType as InterfaceType; 2121 InterfaceType propagatedType = identifier.propagatedType as InterfaceType;
2119 expect(propagatedType.element, same(typeProvider.mapType.element)); 2122 expect(propagatedType.element, same(typeProvider.mapType.element));
2120 List<DartType> typeArguments = propagatedType.typeArguments; 2123 List<DartType> typeArguments = propagatedType.typeArguments;
2121 expect(typeArguments, hasLength(2)); 2124 expect(typeArguments, hasLength(2));
2122 expect(typeArguments[0], same(typeProvider.dynamicType)); 2125 expect(typeArguments[0], same(typeProvider.dynamicType));
2123 expect(typeArguments[1], same(typeProvider.dynamicType)); 2126 expect(typeArguments[1], same(typeProvider.dynamicType));
2124 } 2127 }
2125 2128
2126 void test_mergePropagatedTypes_afterIfThen_different() { 2129 test_mergePropagatedTypes_afterIfThen_different() async {
2127 String code = r''' 2130 String code = r'''
2128 main() { 2131 main() {
2129 var v = 0; 2132 var v = 0;
2130 if (v != null) { 2133 if (v != null) {
2131 v = ''; 2134 v = '';
2132 } 2135 }
2133 return v; 2136 return v;
2134 }'''; 2137 }''';
2135 { 2138 {
2136 SimpleIdentifier identifier = findMarkedIdentifier(code, "v;"); 2139 SimpleIdentifier identifier = await findMarkedIdentifier(code, "v;");
2137 expect(identifier.propagatedType, null); 2140 expect(identifier.propagatedType, null);
2138 } 2141 }
2139 { 2142 {
2140 SimpleIdentifier identifier = findMarkedIdentifier(code, "v = '';"); 2143 SimpleIdentifier identifier =
2144 await findMarkedIdentifier(code, "v = '';");
2141 expect(identifier.propagatedType, typeProvider.stringType); 2145 expect(identifier.propagatedType, typeProvider.stringType);
2142 } 2146 }
2143 } 2147 }
2144 2148
2145 void test_mergePropagatedTypes_afterIfThen_same() { 2149 test_mergePropagatedTypes_afterIfThen_same() async {
2146 assertTypeOfMarkedExpression( 2150 await assertTypeOfMarkedExpression(
2147 r''' 2151 r'''
2148 main() { 2152 main() {
2149 var v = 1; 2153 var v = 1;
2150 if (v != null) { 2154 if (v != null) {
2151 v = 2; 2155 v = 2;
2152 } 2156 }
2153 return v; // marker 2157 return v; // marker
2154 }''', 2158 }''',
2155 null, 2159 null,
2156 typeProvider.intType); 2160 typeProvider.intType);
2157 } 2161 }
2158 2162
2159 void test_mergePropagatedTypes_afterIfThenElse_different() { 2163 test_mergePropagatedTypes_afterIfThenElse_different() async {
2160 assertTypeOfMarkedExpression( 2164 await assertTypeOfMarkedExpression(
2161 r''' 2165 r'''
2162 main() { 2166 main() {
2163 var v = 1; 2167 var v = 1;
2164 if (v != null) { 2168 if (v != null) {
2165 v = 2; 2169 v = 2;
2166 } else { 2170 } else {
2167 v = '3'; 2171 v = '3';
2168 } 2172 }
2169 return v; // marker 2173 return v; // marker
2170 }''', 2174 }''',
2171 null, 2175 null,
2172 null); 2176 null);
2173 } 2177 }
2174 2178
2175 void test_mergePropagatedTypes_afterIfThenElse_same() { 2179 test_mergePropagatedTypes_afterIfThenElse_same() async {
2176 assertTypeOfMarkedExpression( 2180 await assertTypeOfMarkedExpression(
2177 r''' 2181 r'''
2178 main() { 2182 main() {
2179 var v = 1; 2183 var v = 1;
2180 if (v != null) { 2184 if (v != null) {
2181 v = 2; 2185 v = 2;
2182 } else { 2186 } else {
2183 v = 3; 2187 v = 3;
2184 } 2188 }
2185 return v; // marker 2189 return v; // marker
2186 }''', 2190 }''',
2187 null, 2191 null,
2188 typeProvider.intType); 2192 typeProvider.intType);
2189 } 2193 }
2190 2194
2191 void test_mergePropagatedTypesAtJoinPoint_4() { 2195 test_mergePropagatedTypesAtJoinPoint_4() async {
2192 // https://code.google.com/p/dart/issues/detail?id=19929 2196 // https://code.google.com/p/dart/issues/detail?id=19929
2193 assertTypeOfMarkedExpression( 2197 await assertTypeOfMarkedExpression(
2194 r''' 2198 r'''
2195 f5(x) { 2199 f5(x) {
2196 var y = []; 2200 var y = [];
2197 if (x) { 2201 if (x) {
2198 y = 0; 2202 y = 0;
2199 } else { 2203 } else {
2200 return y; 2204 return y;
2201 } 2205 }
2202 // Propagated type is [int] here: correct. 2206 // Propagated type is [int] here: correct.
2203 return y; // marker 2207 return y; // marker
2204 }''', 2208 }''',
2205 null, 2209 null,
2206 typeProvider.intType); 2210 typeProvider.intType);
2207 } 2211 }
2208 2212
2209 void test_mutatedOutsideScope() { 2213 test_mutatedOutsideScope() async {
2210 // https://code.google.com/p/dart/issues/detail?id=22732 2214 // https://code.google.com/p/dart/issues/detail?id=22732
2211 Source source = addSource(r''' 2215 Source source = addSource(r'''
2212 class Base { 2216 class Base {
2213 } 2217 }
2214 2218
2215 class Derived extends Base { 2219 class Derived extends Base {
2216 get y => null; 2220 get y => null;
2217 } 2221 }
2218 2222
2219 class C { 2223 class C {
2220 void f() { 2224 void f() {
2221 Base x = null; 2225 Base x = null;
2222 if (x is Derived) { 2226 if (x is Derived) {
2223 print(x.y); // BAD 2227 print(x.y); // BAD
2224 } 2228 }
2225 x = null; 2229 x = null;
2226 } 2230 }
2227 } 2231 }
2228 2232
2229 void g() { 2233 void g() {
2230 Base x = null; 2234 Base x = null;
2231 if (x is Derived) { 2235 if (x is Derived) {
2232 print(x.y); // GOOD 2236 print(x.y); // GOOD
2233 } 2237 }
2234 x = null; 2238 x = null;
2235 }'''); 2239 }''');
2236 assertNoErrors(source); 2240 await assertNoErrors(source);
2237 } 2241 }
2238 2242
2239 void test_objectAccessInference_disabled_for_library_prefix() { 2243 test_objectAccessInference_disabled_for_library_prefix() async {
2240 String name = 'hashCode'; 2244 String name = 'hashCode';
2241 addNamedSource( 2245 addNamedSource(
2242 '/helper.dart', 2246 '/helper.dart',
2243 ''' 2247 '''
2244 library helper; 2248 library helper;
2245 dynamic get $name => 42; 2249 dynamic get $name => 42;
2246 '''); 2250 ''');
2247 String code = ''' 2251 String code = '''
2248 import 'helper.dart' as helper; 2252 import 'helper.dart' as helper;
2249 main() { 2253 main() {
2250 helper.$name; // marker 2254 helper.$name; // marker
2251 }'''; 2255 }''';
2252 2256
2253 SimpleIdentifier id = findMarkedIdentifier(code, "; // marker"); 2257 SimpleIdentifier id = await findMarkedIdentifier(code, "; // marker");
2254 PrefixedIdentifier prefixedId = id.parent; 2258 PrefixedIdentifier prefixedId = id.parent;
2255 expect(id.staticType, typeProvider.dynamicType); 2259 expect(id.staticType, typeProvider.dynamicType);
2256 expect(prefixedId.staticType, typeProvider.dynamicType); 2260 expect(prefixedId.staticType, typeProvider.dynamicType);
2257 } 2261 }
2258 2262
2259 void test_objectAccessInference_disabled_for_local_getter() { 2263 test_objectAccessInference_disabled_for_local_getter() async {
2260 String name = 'hashCode'; 2264 String name = 'hashCode';
2261 String code = ''' 2265 String code = '''
2262 dynamic get $name => null; 2266 dynamic get $name => null;
2263 main() { 2267 main() {
2264 $name; // marker 2268 $name; // marker
2265 }'''; 2269 }''';
2266 2270
2267 SimpleIdentifier getter = findMarkedIdentifier(code, "; // marker"); 2271 SimpleIdentifier getter = await findMarkedIdentifier(code, "; // marker");
2268 expect(getter.staticType, typeProvider.dynamicType); 2272 expect(getter.staticType, typeProvider.dynamicType);
2269 } 2273 }
2270 2274
2271 void test_objectAccessInference_enabled_for_cascades() { 2275 test_objectAccessInference_enabled_for_cascades() async {
2272 String name = 'hashCode'; 2276 String name = 'hashCode';
2273 String code = ''' 2277 String code = '''
2274 main() { 2278 main() {
2275 dynamic obj; 2279 dynamic obj;
2276 obj..$name..$name; // marker 2280 obj..$name..$name; // marker
2277 }'''; 2281 }''';
2278 PropertyAccess access = findMarkedIdentifier(code, "; // marker").parent; 2282 PropertyAccess access =
2283 (await findMarkedIdentifier(code, "; // marker")).parent;
2279 expect(access.staticType, typeProvider.dynamicType); 2284 expect(access.staticType, typeProvider.dynamicType);
2280 expect(access.realTarget.staticType, typeProvider.dynamicType); 2285 expect(access.realTarget.staticType, typeProvider.dynamicType);
2281 } 2286 }
2282 2287
2283 void test_objectMethodInference_disabled_for_library_prefix() { 2288 test_objectMethodInference_disabled_for_library_prefix() async {
2284 String name = 'toString'; 2289 String name = 'toString';
2285 addNamedSource( 2290 addNamedSource(
2286 '/helper.dart', 2291 '/helper.dart',
2287 ''' 2292 '''
2288 library helper; 2293 library helper;
2289 dynamic $name = (int x) => x + 42'); 2294 dynamic $name = (int x) => x + 42');
2290 '''); 2295 ''');
2291 String code = ''' 2296 String code = '''
2292 import 'helper.dart' as helper; 2297 import 'helper.dart' as helper;
2293 main() { 2298 main() {
2294 helper.$name(); // marker 2299 helper.$name(); // marker
2295 }'''; 2300 }''';
2296 SimpleIdentifier methodName = findMarkedIdentifier(code, "(); // marker"); 2301 SimpleIdentifier methodName =
2302 await findMarkedIdentifier(code, "(); // marker");
2297 MethodInvocation methodInvoke = methodName.parent; 2303 MethodInvocation methodInvoke = methodName.parent;
2298 expect(methodName.staticType, typeProvider.dynamicType); 2304 expect(methodName.staticType, typeProvider.dynamicType);
2299 expect(methodInvoke.staticType, typeProvider.dynamicType); 2305 expect(methodInvoke.staticType, typeProvider.dynamicType);
2300 } 2306 }
2301 2307
2302 void test_objectMethodInference_disabled_for_local_function() { 2308 test_objectMethodInference_disabled_for_local_function() async {
2303 String name = 'toString'; 2309 String name = 'toString';
2304 String code = ''' 2310 String code = '''
2305 main() { 2311 main() {
2306 dynamic $name = () => null; 2312 dynamic $name = () => null;
2307 $name(); // marker 2313 $name(); // marker
2308 }'''; 2314 }''';
2309 SimpleIdentifier identifier = findMarkedIdentifier(code, "$name = "); 2315 SimpleIdentifier identifier = await findMarkedIdentifier(code, "$name = ");
2310 expect(identifier.staticType, typeProvider.dynamicType); 2316 expect(identifier.staticType, typeProvider.dynamicType);
2311 2317
2312 SimpleIdentifier methodName = findMarkedIdentifier(code, "(); // marker"); 2318 SimpleIdentifier methodName =
2319 await findMarkedIdentifier(code, "(); // marker");
2313 MethodInvocation methodInvoke = methodName.parent; 2320 MethodInvocation methodInvoke = methodName.parent;
2314 expect(methodName.staticType, typeProvider.dynamicType); 2321 expect(methodName.staticType, typeProvider.dynamicType);
2315 expect(methodInvoke.staticType, typeProvider.dynamicType); 2322 expect(methodInvoke.staticType, typeProvider.dynamicType);
2316 } 2323 }
2317 2324
2318 void test_objectMethodInference_enabled_for_cascades() { 2325 test_objectMethodInference_enabled_for_cascades() async {
2319 String name = 'toString'; 2326 String name = 'toString';
2320 String code = ''' 2327 String code = '''
2321 main() { 2328 main() {
2322 dynamic obj; 2329 dynamic obj;
2323 obj..$name()..$name(); // marker 2330 obj..$name()..$name(); // marker
2324 }'''; 2331 }''';
2325 SimpleIdentifier methodName = findMarkedIdentifier(code, "(); // marker"); 2332 SimpleIdentifier methodName =
2333 await findMarkedIdentifier(code, "(); // marker");
2326 MethodInvocation methodInvoke = methodName.parent; 2334 MethodInvocation methodInvoke = methodName.parent;
2327 2335
2328 expect(methodInvoke.staticType, typeProvider.dynamicType); 2336 expect(methodInvoke.staticType, typeProvider.dynamicType);
2329 expect(methodInvoke.realTarget.staticType, typeProvider.dynamicType); 2337 expect(methodInvoke.realTarget.staticType, typeProvider.dynamicType);
2330 } 2338 }
2331 2339
2332 void test_objectMethodOnDynamicExpression_doubleEquals() { 2340 test_objectMethodOnDynamicExpression_doubleEquals() async {
2333 // https://code.google.com/p/dart/issues/detail?id=20342 2341 // https://code.google.com/p/dart/issues/detail?id=20342
2334 // 2342 //
2335 // This was not actually part of Issue 20342, since the spec specifies a 2343 // This was not actually part of Issue 20342, since the spec specifies a
2336 // static type of [bool] for [==] comparison and the implementation 2344 // static type of [bool] for [==] comparison and the implementation
2337 // was already consistent with the spec there. But, it's another 2345 // was already consistent with the spec there. But, it's another
2338 // [Object] method, so it's included here. 2346 // [Object] method, so it's included here.
2339 assertTypeOfMarkedExpression( 2347 await assertTypeOfMarkedExpression(
2340 r''' 2348 r'''
2341 f1(x) { 2349 f1(x) {
2342 var v = (x == x); 2350 var v = (x == x);
2343 return v; // marker 2351 return v; // marker
2344 }''', 2352 }''',
2345 null, 2353 null,
2346 typeProvider.boolType); 2354 typeProvider.boolType);
2347 } 2355 }
2348 2356
2349 void test_objectMethodOnDynamicExpression_hashCode() { 2357 test_objectMethodOnDynamicExpression_hashCode() async {
2350 // https://code.google.com/p/dart/issues/detail?id=20342 2358 // https://code.google.com/p/dart/issues/detail?id=20342
2351 assertTypeOfMarkedExpression( 2359 await assertTypeOfMarkedExpression(
2352 r''' 2360 r'''
2353 f1(x) { 2361 f1(x) {
2354 var v = x.hashCode; 2362 var v = x.hashCode;
2355 return v; // marker 2363 return v; // marker
2356 }''', 2364 }''',
2357 null, 2365 null,
2358 typeProvider.intType); 2366 typeProvider.intType);
2359 } 2367 }
2360 2368
2361 void test_objectMethodOnDynamicExpression_runtimeType() { 2369 test_objectMethodOnDynamicExpression_runtimeType() async {
2362 // https://code.google.com/p/dart/issues/detail?id=20342 2370 // https://code.google.com/p/dart/issues/detail?id=20342
2363 assertTypeOfMarkedExpression( 2371 await assertTypeOfMarkedExpression(
2364 r''' 2372 r'''
2365 f1(x) { 2373 f1(x) {
2366 var v = x.runtimeType; 2374 var v = x.runtimeType;
2367 return v; // marker 2375 return v; // marker
2368 }''', 2376 }''',
2369 null, 2377 null,
2370 typeProvider.typeType); 2378 typeProvider.typeType);
2371 } 2379 }
2372 2380
2373 void test_objectMethodOnDynamicExpression_toString() { 2381 test_objectMethodOnDynamicExpression_toString() async {
2374 // https://code.google.com/p/dart/issues/detail?id=20342 2382 // https://code.google.com/p/dart/issues/detail?id=20342
2375 assertTypeOfMarkedExpression( 2383 await assertTypeOfMarkedExpression(
2376 r''' 2384 r'''
2377 f1(x) { 2385 f1(x) {
2378 var v = x.toString(); 2386 var v = x.toString();
2379 return v; // marker 2387 return v; // marker
2380 }''', 2388 }''',
2381 null, 2389 null,
2382 typeProvider.stringType); 2390 typeProvider.stringType);
2383 } 2391 }
2384 2392
2385 void test_propagatedReturnType_localFunction() { 2393 test_propagatedReturnType_localFunction() async {
2386 String code = r''' 2394 String code = r'''
2387 main() { 2395 main() {
2388 f() => 42; 2396 f() => 42;
2389 var v = f(); 2397 var v = f();
2390 }'''; 2398 }''';
2391 assertPropagatedAssignedType( 2399 await assertPropagatedAssignedType(
2392 code, typeProvider.dynamicType, typeProvider.intType); 2400 code, typeProvider.dynamicType, typeProvider.intType);
2393 } 2401 }
2394 2402
2395 void test_query() { 2403 test_query() async {
2396 Source source = addSource(r''' 2404 Source source = addSource(r'''
2397 import 'dart:html'; 2405 import 'dart:html';
2398 2406
2399 main() { 2407 main() {
2400 var v1 = query('a'); 2408 var v1 = query('a');
2401 var v2 = query('A'); 2409 var v2 = query('A');
2402 var v3 = query('body:active'); 2410 var v3 = query('body:active');
2403 var v4 = query('button[foo="bar"]'); 2411 var v4 = query('button[foo="bar"]');
2404 var v5 = query('div.class'); 2412 var v5 = query('div.class');
2405 var v6 = query('input#id'); 2413 var v6 = query('input#id');
2406 var v7 = query('select#id'); 2414 var v7 = query('select#id');
2407 // invocation of method 2415 // invocation of method
2408 var m1 = document.query('div'); 2416 var m1 = document.query('div');
2409 // unsupported currently 2417 // unsupported currently
2410 var b1 = query('noSuchTag'); 2418 var b1 = query('noSuchTag');
2411 var b2 = query('DART_EDITOR_NO_SUCH_TYPE'); 2419 var b2 = query('DART_EDITOR_NO_SUCH_TYPE');
2412 var b3 = query('body div'); 2420 var b3 = query('body div');
2413 return [v1, v2, v3, v4, v5, v6, v7, m1, b1, b2, b3]; 2421 return [v1, v2, v3, v4, v5, v6, v7, m1, b1, b2, b3];
2414 }'''); 2422 }''');
2415 LibraryElement library = resolve2(source); 2423 LibraryElement library = resolve2(source);
2416 assertNoErrors(source); 2424 await assertNoErrors(source);
2417 verify([source]); 2425 verify([source]);
2418 CompilationUnit unit = resolveCompilationUnit(source, library); 2426 CompilationUnit unit = resolveCompilationUnit(source, library);
2419 FunctionDeclaration main = unit.declarations[0] as FunctionDeclaration; 2427 FunctionDeclaration main = unit.declarations[0] as FunctionDeclaration;
2420 BlockFunctionBody body = main.functionExpression.body as BlockFunctionBody; 2428 BlockFunctionBody body = main.functionExpression.body as BlockFunctionBody;
2421 ReturnStatement statement = body.block.statements[11] as ReturnStatement; 2429 ReturnStatement statement = body.block.statements[11] as ReturnStatement;
2422 NodeList<Expression> elements = 2430 NodeList<Expression> elements =
2423 (statement.expression as ListLiteral).elements; 2431 (statement.expression as ListLiteral).elements;
2424 expect(resolutionMap.propagatedTypeForExpression(elements[0]).name, 2432 expect(resolutionMap.propagatedTypeForExpression(elements[0]).name,
2425 "AnchorElement"); 2433 "AnchorElement");
2426 expect(resolutionMap.propagatedTypeForExpression(elements[1]).name, 2434 expect(resolutionMap.propagatedTypeForExpression(elements[1]).name,
(...skipping 14 matching lines...) Expand all
2441 resolutionMap.propagatedTypeForExpression(elements[8]).name, "Element"); 2449 resolutionMap.propagatedTypeForExpression(elements[8]).name, "Element");
2442 expect( 2450 expect(
2443 resolutionMap.propagatedTypeForExpression(elements[9]).name, "Element"); 2451 resolutionMap.propagatedTypeForExpression(elements[9]).name, "Element");
2444 expect(resolutionMap.propagatedTypeForExpression(elements[10]).name, 2452 expect(resolutionMap.propagatedTypeForExpression(elements[10]).name,
2445 "Element"); 2453 "Element");
2446 } 2454 }
2447 } 2455 }
2448 2456
2449 @reflectiveTest 2457 @reflectiveTest
2450 class TypeProviderImplTest extends EngineTestCase { 2458 class TypeProviderImplTest extends EngineTestCase {
2451 void test_creation() { 2459 test_creation() async {
2452 // 2460 //
2453 // Create a mock library element with the types expected to be in dart:core. 2461 // Create a mock library element with the types expected to be in dart:core.
2454 // We cannot use either ElementFactory or TestTypeProvider (which uses 2462 // We cannot use either ElementFactory or TestTypeProvider (which uses
2455 // ElementFactory) because we side-effect the elements in ways that would 2463 // ElementFactory) because we side-effect the elements in ways that would
2456 // break other tests. 2464 // break other tests.
2457 // 2465 //
2458 InterfaceType objectType = _classElement("Object", null).type; 2466 InterfaceType objectType = _classElement("Object", null).type;
2459 InterfaceType boolType = _classElement("bool", objectType).type; 2467 InterfaceType boolType = _classElement("bool", objectType).type;
2460 InterfaceType numType = _classElement("num", objectType).type; 2468 InterfaceType numType = _classElement("num", objectType).type;
2461 InterfaceType doubleType = _classElement("double", numType).type; 2469 InterfaceType doubleType = _classElement("double", numType).type;
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
2560 /** 2568 /**
2561 * The library scope in which types are to be resolved. 2569 * The library scope in which types are to be resolved.
2562 */ 2570 */
2563 LibraryScope libraryScope; 2571 LibraryScope libraryScope;
2564 2572
2565 /** 2573 /**
2566 * The visitor used to resolve types needed to form the type hierarchy. 2574 * The visitor used to resolve types needed to form the type hierarchy.
2567 */ 2575 */
2568 TypeResolverVisitor _visitor; 2576 TypeResolverVisitor _visitor;
2569 2577
2570 void fail_visitConstructorDeclaration() { 2578 fail_visitConstructorDeclaration() async {
2571 fail("Not yet tested"); 2579 fail("Not yet tested");
2572 _listener.assertNoErrors(); 2580 _listener.assertNoErrors();
2573 } 2581 }
2574 2582
2575 void fail_visitFunctionTypeAlias() { 2583 fail_visitFunctionTypeAlias() async {
2576 fail("Not yet tested"); 2584 fail("Not yet tested");
2577 _listener.assertNoErrors(); 2585 _listener.assertNoErrors();
2578 } 2586 }
2579 2587
2580 void fail_visitVariableDeclaration() { 2588 fail_visitVariableDeclaration() async {
2581 fail("Not yet tested"); 2589 fail("Not yet tested");
2582 ClassElement type = ElementFactory.classElement2("A"); 2590 ClassElement type = ElementFactory.classElement2("A");
2583 VariableDeclaration node = AstTestFactory.variableDeclaration("a"); 2591 VariableDeclaration node = AstTestFactory.variableDeclaration("a");
2584 AstTestFactory 2592 AstTestFactory
2585 .variableDeclarationList(null, AstTestFactory.typeName(type), [node]); 2593 .variableDeclarationList(null, AstTestFactory.typeName(type), [node]);
2586 //resolve(node); 2594 //resolve(node);
2587 expect(node.name.staticType, same(type.type)); 2595 expect(node.name.staticType, same(type.type));
2588 _listener.assertNoErrors(); 2596 _listener.assertNoErrors();
2589 } 2597 }
2590 2598
2591 void setUp() { 2599 void setUp() {
2592 _listener = new GatheringErrorListener(); 2600 _listener = new GatheringErrorListener();
2593 MemoryResourceProvider resourceProvider = new MemoryResourceProvider(); 2601 MemoryResourceProvider resourceProvider = new MemoryResourceProvider();
2594 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore( 2602 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(
2595 resourceProvider: resourceProvider); 2603 resourceProvider: resourceProvider);
2596 Source librarySource = 2604 Source librarySource =
2597 new FileSource(resourceProvider.getFile("/lib.dart")); 2605 new FileSource(resourceProvider.getFile("/lib.dart"));
2598 LibraryElementImpl element = new LibraryElementImpl.forNode( 2606 LibraryElementImpl element = new LibraryElementImpl.forNode(
2599 context, AstTestFactory.libraryIdentifier2(["lib"])); 2607 context, AstTestFactory.libraryIdentifier2(["lib"]));
2600 element.definingCompilationUnit = 2608 element.definingCompilationUnit =
2601 new CompilationUnitElementImpl("lib.dart"); 2609 new CompilationUnitElementImpl("lib.dart");
2602 _typeProvider = new TestTypeProvider(); 2610 _typeProvider = new TestTypeProvider();
2603 libraryScope = new LibraryScope(element); 2611 libraryScope = new LibraryScope(element);
2604 _visitor = new TypeResolverVisitor( 2612 _visitor = new TypeResolverVisitor(
2605 element, librarySource, _typeProvider, _listener, 2613 element, librarySource, _typeProvider, _listener,
2606 nameScope: libraryScope); 2614 nameScope: libraryScope);
2607 } 2615 }
2608 2616
2609 void test_modeApi() { 2617 test_modeApi() async {
2610 CompilationUnit unit = ParserTestCase.parseCompilationUnit(r''' 2618 CompilationUnit unit = ParserTestCase.parseCompilationUnit(r'''
2611 class C extends A with A implements A { 2619 class C extends A with A implements A {
2612 A f = new A(); 2620 A f = new A();
2613 A m() { 2621 A m() {
2614 A v1; 2622 A v1;
2615 } 2623 }
2616 } 2624 }
2617 A f([A p = const A()]) { 2625 A f([A p = const A()]) {
2618 A v2; 2626 A v2;
2619 } 2627 }
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
2700 var vd = unit.declarations[2] as TopLevelVariableDeclaration; 2708 var vd = unit.declarations[2] as TopLevelVariableDeclaration;
2701 // The type is resolved. 2709 // The type is resolved.
2702 expect(vd.variables.type.toString(), 'A'); 2710 expect(vd.variables.type.toString(), 'A');
2703 // The initializer is not resolved. 2711 // The initializer is not resolved.
2704 VariableDeclaration v = vd.variables.variables[0]; 2712 VariableDeclaration v = vd.variables.variables[0];
2705 var vi = v.initializer as InstanceCreationExpression; 2713 var vi = v.initializer as InstanceCreationExpression;
2706 expect(vi.constructorName.type.type, isNull); 2714 expect(vi.constructorName.type.type, isNull);
2707 } 2715 }
2708 } 2716 }
2709 2717
2710 void test_modeLocal_noContext() { 2718 test_modeLocal_noContext() async {
2711 CompilationUnit unit; 2719 CompilationUnit unit;
2712 _resolveTypeModeLocal( 2720 _resolveTypeModeLocal(
2713 r''' 2721 r'''
2714 class C { 2722 class C {
2715 A f = new A(); 2723 A f = new A();
2716 A m([A p = const A()]) { 2724 A m([A p = const A()]) {
2717 A v; 2725 A v;
2718 } 2726 }
2719 } 2727 }
2720 A f([A p = const A()]) { 2728 A f([A p = const A()]) {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
2814 var g = unit.declarations[3] as FunctionDeclaration; 2822 var g = unit.declarations[3] as FunctionDeclaration;
2815 // The return type is not resolved. 2823 // The return type is not resolved.
2816 expect(g.returnType.type, isNull); 2824 expect(g.returnType.type, isNull);
2817 // The body is resolved. 2825 // The body is resolved.
2818 var gb = g.functionExpression.body as ExpressionFunctionBody; 2826 var gb = g.functionExpression.body as ExpressionFunctionBody;
2819 var ge = gb.expression as InstanceCreationExpression; 2827 var ge = gb.expression as InstanceCreationExpression;
2820 expect(ge.constructorName.type.type.toString(), 'A'); 2828 expect(ge.constructorName.type.type.toString(), 'A');
2821 } 2829 }
2822 } 2830 }
2823 2831
2824 void test_modeLocal_withContext_bad_methodBody() { 2832 test_modeLocal_withContext_bad_methodBody() async {
2825 expect(() { 2833 expect(() {
2826 _resolveTypeModeLocal( 2834 _resolveTypeModeLocal(
2827 r''' 2835 r'''
2828 class C<T1> { 2836 class C<T1> {
2829 A m<T2>() { 2837 A m<T2>() {
2830 T1 v1; 2838 T1 v1;
2831 T2 v2; 2839 T2 v2;
2832 } 2840 }
2833 } 2841 }
2834 ''', (CompilationUnit u) { 2842 ''', (CompilationUnit u) {
2835 var c = u.declarations[0] as ClassDeclaration; 2843 var c = u.declarations[0] as ClassDeclaration;
2836 var m = c.members[0] as MethodDeclaration; 2844 var m = c.members[0] as MethodDeclaration;
2837 var mb = m.body as BlockFunctionBody; 2845 var mb = m.body as BlockFunctionBody;
2838 return mb; 2846 return mb;
2839 }); 2847 });
2840 }, throwsStateError); 2848 }, throwsStateError);
2841 } 2849 }
2842 2850
2843 void test_modeLocal_withContext_bad_topLevelVariable_declaration() { 2851 test_modeLocal_withContext_bad_topLevelVariable_declaration() async {
2844 expect(() { 2852 expect(() {
2845 _resolveTypeModeLocal( 2853 _resolveTypeModeLocal(
2846 r''' 2854 r'''
2847 var v = new A(); 2855 var v = new A();
2848 ''', (CompilationUnit u) { 2856 ''', (CompilationUnit u) {
2849 var tlv = u.declarations[0] as TopLevelVariableDeclaration; 2857 var tlv = u.declarations[0] as TopLevelVariableDeclaration;
2850 return tlv.variables.variables[0]; 2858 return tlv.variables.variables[0];
2851 }); 2859 });
2852 }, throwsStateError); 2860 }, throwsStateError);
2853 } 2861 }
2854 2862
2855 void test_modeLocal_withContext_bad_topLevelVariable_initializer() { 2863 test_modeLocal_withContext_bad_topLevelVariable_initializer() async {
2856 expect(() { 2864 expect(() {
2857 _resolveTypeModeLocal( 2865 _resolveTypeModeLocal(
2858 r''' 2866 r'''
2859 var v = new A(); 2867 var v = new A();
2860 ''', (CompilationUnit u) { 2868 ''', (CompilationUnit u) {
2861 var tlv = u.declarations[0] as TopLevelVariableDeclaration; 2869 var tlv = u.declarations[0] as TopLevelVariableDeclaration;
2862 return tlv.variables.variables[0].initializer; 2870 return tlv.variables.variables[0].initializer;
2863 }); 2871 });
2864 }, throwsStateError); 2872 }, throwsStateError);
2865 } 2873 }
2866 2874
2867 void test_modeLocal_withContext_class() { 2875 test_modeLocal_withContext_class() async {
2868 ClassDeclaration c; 2876 ClassDeclaration c;
2869 _resolveTypeModeLocal( 2877 _resolveTypeModeLocal(
2870 r''' 2878 r'''
2871 class C<T1> { 2879 class C<T1> {
2872 A m<T2>() { 2880 A m<T2>() {
2873 T1 v1; 2881 T1 v1;
2874 T2 v2; 2882 T2 v2;
2875 } 2883 }
2876 } 2884 }
2877 ''', (CompilationUnit u) { 2885 ''', (CompilationUnit u) {
(...skipping 14 matching lines...) Expand all
2892 expect(vd.variables.type.type.toString(), 'T1'); 2900 expect(vd.variables.type.type.toString(), 'T1');
2893 } 2901 }
2894 2902
2895 // The type of "v2" is resolved. 2903 // The type of "v2" is resolved.
2896 { 2904 {
2897 var vd = ms[1] as VariableDeclarationStatement; 2905 var vd = ms[1] as VariableDeclarationStatement;
2898 expect(vd.variables.type.type.toString(), 'T2'); 2906 expect(vd.variables.type.type.toString(), 'T2');
2899 } 2907 }
2900 } 2908 }
2901 2909
2902 void test_modeLocal_withContext_inClass_constructor() { 2910 test_modeLocal_withContext_inClass_constructor() async {
2903 ConstructorDeclaration cc; 2911 ConstructorDeclaration cc;
2904 _resolveTypeModeLocal( 2912 _resolveTypeModeLocal(
2905 r''' 2913 r'''
2906 class C<T> { 2914 class C<T> {
2907 C() { 2915 C() {
2908 T v1; 2916 T v1;
2909 } 2917 }
2910 } 2918 }
2911 ''', (CompilationUnit u) { 2919 ''', (CompilationUnit u) {
2912 var c = u.declarations[0] as ClassDeclaration; 2920 var c = u.declarations[0] as ClassDeclaration;
2913 cc = c.members[0] as ConstructorDeclaration; 2921 cc = c.members[0] as ConstructorDeclaration;
2914 return cc; 2922 return cc;
2915 }); 2923 });
2916 2924
2917 var ccb = cc.body as BlockFunctionBody; 2925 var ccb = cc.body as BlockFunctionBody;
2918 var ccs = ccb.block.statements; 2926 var ccs = ccb.block.statements;
2919 2927
2920 // The type of "v" is resolved. 2928 // The type of "v" is resolved.
2921 { 2929 {
2922 var vd = ccs[0] as VariableDeclarationStatement; 2930 var vd = ccs[0] as VariableDeclarationStatement;
2923 expect(vd.variables.type.type.toString(), 'T'); 2931 expect(vd.variables.type.type.toString(), 'T');
2924 } 2932 }
2925 } 2933 }
2926 2934
2927 void test_modeLocal_withContext_inClass_method() { 2935 test_modeLocal_withContext_inClass_method() async {
2928 MethodDeclaration m; 2936 MethodDeclaration m;
2929 _resolveTypeModeLocal( 2937 _resolveTypeModeLocal(
2930 r''' 2938 r'''
2931 class C<T1> { 2939 class C<T1> {
2932 A m<T2>() { 2940 A m<T2>() {
2933 T1 v1; 2941 T1 v1;
2934 T2 v2; 2942 T2 v2;
2935 } 2943 }
2936 } 2944 }
2937 ''', (CompilationUnit u) { 2945 ''', (CompilationUnit u) {
(...skipping 14 matching lines...) Expand all
2952 expect(vd.variables.type.type.toString(), 'T1'); 2960 expect(vd.variables.type.type.toString(), 'T1');
2953 } 2961 }
2954 2962
2955 // The type of "v2" is resolved. 2963 // The type of "v2" is resolved.
2956 { 2964 {
2957 var vd = ms[1] as VariableDeclarationStatement; 2965 var vd = ms[1] as VariableDeclarationStatement;
2958 expect(vd.variables.type.type.toString(), 'T2'); 2966 expect(vd.variables.type.type.toString(), 'T2');
2959 } 2967 }
2960 } 2968 }
2961 2969
2962 void test_modeLocal_withContext_topLevelFunction() { 2970 test_modeLocal_withContext_topLevelFunction() async {
2963 FunctionDeclaration f; 2971 FunctionDeclaration f;
2964 _resolveTypeModeLocal( 2972 _resolveTypeModeLocal(
2965 r''' 2973 r'''
2966 A m<T>() { 2974 A m<T>() {
2967 T v; 2975 T v;
2968 } 2976 }
2969 ''', (CompilationUnit u) { 2977 ''', (CompilationUnit u) {
2970 f = u.declarations[0] as FunctionDeclaration; 2978 f = u.declarations[0] as FunctionDeclaration;
2971 return f; 2979 return f;
2972 }); 2980 });
2973 2981
2974 // The return type of "f" is not resolved. 2982 // The return type of "f" is not resolved.
2975 expect(f.returnType.type, isNull); 2983 expect(f.returnType.type, isNull);
2976 2984
2977 var fb = f.functionExpression.body as BlockFunctionBody; 2985 var fb = f.functionExpression.body as BlockFunctionBody;
2978 var fs = fb.block.statements; 2986 var fs = fb.block.statements;
2979 2987
2980 // The type of "v" is resolved. 2988 // The type of "v" is resolved.
2981 var vd = fs[0] as VariableDeclarationStatement; 2989 var vd = fs[0] as VariableDeclarationStatement;
2982 expect(vd.variables.type.type.toString(), 'T'); 2990 expect(vd.variables.type.type.toString(), 'T');
2983 } 2991 }
2984 2992
2985 void test_modeLocal_withContext_topLevelVariable() { 2993 test_modeLocal_withContext_topLevelVariable() async {
2986 TopLevelVariableDeclaration v; 2994 TopLevelVariableDeclaration v;
2987 _resolveTypeModeLocal( 2995 _resolveTypeModeLocal(
2988 r''' 2996 r'''
2989 A v = new A(); 2997 A v = new A();
2990 ''', (CompilationUnit u) { 2998 ''', (CompilationUnit u) {
2991 v = u.declarations[0] as TopLevelVariableDeclaration; 2999 v = u.declarations[0] as TopLevelVariableDeclaration;
2992 return v; 3000 return v;
2993 }); 3001 });
2994 3002
2995 // The type of "v" is not resolved. 3003 // The type of "v" is not resolved.
2996 expect(v.variables.type.type, isNull); 3004 expect(v.variables.type.type, isNull);
2997 3005
2998 // The type of "v" initializer is resolved. 3006 // The type of "v" initializer is resolved.
2999 var vi = v.variables.variables[0].initializer as InstanceCreationExpression; 3007 var vi = v.variables.variables[0].initializer as InstanceCreationExpression;
3000 expect(vi.constructorName.type.type.toString(), 'A'); 3008 expect(vi.constructorName.type.type.toString(), 'A');
3001 } 3009 }
3002 3010
3003 void test_visitCatchClause_exception() { 3011 test_visitCatchClause_exception() async {
3004 // catch (e) 3012 // catch (e)
3005 CatchClause clause = AstTestFactory.catchClause("e"); 3013 CatchClause clause = AstTestFactory.catchClause("e");
3006 SimpleIdentifier exceptionParameter = clause.exceptionParameter; 3014 SimpleIdentifier exceptionParameter = clause.exceptionParameter;
3007 exceptionParameter.staticElement = 3015 exceptionParameter.staticElement =
3008 new LocalVariableElementImpl.forNode(exceptionParameter); 3016 new LocalVariableElementImpl.forNode(exceptionParameter);
3009 _resolveCatchClause(clause, _typeProvider.dynamicType, null); 3017 _resolveCatchClause(clause, _typeProvider.dynamicType, null);
3010 _listener.assertNoErrors(); 3018 _listener.assertNoErrors();
3011 } 3019 }
3012 3020
3013 void test_visitCatchClause_exception_stackTrace() { 3021 test_visitCatchClause_exception_stackTrace() async {
3014 // catch (e, s) 3022 // catch (e, s)
3015 CatchClause clause = AstTestFactory.catchClause2("e", "s"); 3023 CatchClause clause = AstTestFactory.catchClause2("e", "s");
3016 SimpleIdentifier exceptionParameter = clause.exceptionParameter; 3024 SimpleIdentifier exceptionParameter = clause.exceptionParameter;
3017 exceptionParameter.staticElement = 3025 exceptionParameter.staticElement =
3018 new LocalVariableElementImpl.forNode(exceptionParameter); 3026 new LocalVariableElementImpl.forNode(exceptionParameter);
3019 SimpleIdentifier stackTraceParameter = clause.stackTraceParameter; 3027 SimpleIdentifier stackTraceParameter = clause.stackTraceParameter;
3020 stackTraceParameter.staticElement = 3028 stackTraceParameter.staticElement =
3021 new LocalVariableElementImpl.forNode(stackTraceParameter); 3029 new LocalVariableElementImpl.forNode(stackTraceParameter);
3022 _resolveCatchClause( 3030 _resolveCatchClause(
3023 clause, _typeProvider.dynamicType, _typeProvider.stackTraceType); 3031 clause, _typeProvider.dynamicType, _typeProvider.stackTraceType);
3024 _listener.assertNoErrors(); 3032 _listener.assertNoErrors();
3025 } 3033 }
3026 3034
3027 void test_visitCatchClause_on_exception() { 3035 test_visitCatchClause_on_exception() async {
3028 // on E catch (e) 3036 // on E catch (e)
3029 ClassElement exceptionElement = ElementFactory.classElement2("E"); 3037 ClassElement exceptionElement = ElementFactory.classElement2("E");
3030 TypeName exceptionType = AstTestFactory.typeName(exceptionElement); 3038 TypeName exceptionType = AstTestFactory.typeName(exceptionElement);
3031 CatchClause clause = AstTestFactory.catchClause4(exceptionType, "e"); 3039 CatchClause clause = AstTestFactory.catchClause4(exceptionType, "e");
3032 SimpleIdentifier exceptionParameter = clause.exceptionParameter; 3040 SimpleIdentifier exceptionParameter = clause.exceptionParameter;
3033 exceptionParameter.staticElement = 3041 exceptionParameter.staticElement =
3034 new LocalVariableElementImpl.forNode(exceptionParameter); 3042 new LocalVariableElementImpl.forNode(exceptionParameter);
3035 _resolveCatchClause( 3043 _resolveCatchClause(
3036 clause, exceptionElement.type, null, [exceptionElement]); 3044 clause, exceptionElement.type, null, [exceptionElement]);
3037 _listener.assertNoErrors(); 3045 _listener.assertNoErrors();
3038 } 3046 }
3039 3047
3040 void test_visitCatchClause_on_exception_stackTrace() { 3048 test_visitCatchClause_on_exception_stackTrace() async {
3041 // on E catch (e, s) 3049 // on E catch (e, s)
3042 ClassElement exceptionElement = ElementFactory.classElement2("E"); 3050 ClassElement exceptionElement = ElementFactory.classElement2("E");
3043 TypeName exceptionType = AstTestFactory.typeName(exceptionElement); 3051 TypeName exceptionType = AstTestFactory.typeName(exceptionElement);
3044 (exceptionType.name as SimpleIdentifier).staticElement = exceptionElement; 3052 (exceptionType.name as SimpleIdentifier).staticElement = exceptionElement;
3045 CatchClause clause = AstTestFactory.catchClause5(exceptionType, "e", "s"); 3053 CatchClause clause = AstTestFactory.catchClause5(exceptionType, "e", "s");
3046 SimpleIdentifier exceptionParameter = clause.exceptionParameter; 3054 SimpleIdentifier exceptionParameter = clause.exceptionParameter;
3047 exceptionParameter.staticElement = 3055 exceptionParameter.staticElement =
3048 new LocalVariableElementImpl.forNode(exceptionParameter); 3056 new LocalVariableElementImpl.forNode(exceptionParameter);
3049 SimpleIdentifier stackTraceParameter = clause.stackTraceParameter; 3057 SimpleIdentifier stackTraceParameter = clause.stackTraceParameter;
3050 stackTraceParameter.staticElement = 3058 stackTraceParameter.staticElement =
3051 new LocalVariableElementImpl.forNode(stackTraceParameter); 3059 new LocalVariableElementImpl.forNode(stackTraceParameter);
3052 _resolveCatchClause(clause, exceptionElement.type, 3060 _resolveCatchClause(clause, exceptionElement.type,
3053 _typeProvider.stackTraceType, [exceptionElement]); 3061 _typeProvider.stackTraceType, [exceptionElement]);
3054 _listener.assertNoErrors(); 3062 _listener.assertNoErrors();
3055 } 3063 }
3056 3064
3057 void test_visitClassDeclaration() { 3065 test_visitClassDeclaration() async {
3058 // class A extends B with C implements D {} 3066 // class A extends B with C implements D {}
3059 // class B {} 3067 // class B {}
3060 // class C {} 3068 // class C {}
3061 // class D {} 3069 // class D {}
3062 ClassElement elementA = ElementFactory.classElement2("A"); 3070 ClassElement elementA = ElementFactory.classElement2("A");
3063 ClassElement elementB = ElementFactory.classElement2("B"); 3071 ClassElement elementB = ElementFactory.classElement2("B");
3064 ClassElement elementC = ElementFactory.classElement2("C"); 3072 ClassElement elementC = ElementFactory.classElement2("C");
3065 ClassElement elementD = ElementFactory.classElement2("D"); 3073 ClassElement elementD = ElementFactory.classElement2("D");
3066 ExtendsClause extendsClause = 3074 ExtendsClause extendsClause =
3067 AstTestFactory.extendsClause(AstTestFactory.typeName(elementB)); 3075 AstTestFactory.extendsClause(AstTestFactory.typeName(elementB));
3068 WithClause withClause = 3076 WithClause withClause =
3069 AstTestFactory.withClause([AstTestFactory.typeName(elementC)]); 3077 AstTestFactory.withClause([AstTestFactory.typeName(elementC)]);
3070 ImplementsClause implementsClause = 3078 ImplementsClause implementsClause =
3071 AstTestFactory.implementsClause([AstTestFactory.typeName(elementD)]); 3079 AstTestFactory.implementsClause([AstTestFactory.typeName(elementD)]);
3072 ClassDeclaration declaration = AstTestFactory.classDeclaration( 3080 ClassDeclaration declaration = AstTestFactory.classDeclaration(
3073 null, "A", null, extendsClause, withClause, implementsClause); 3081 null, "A", null, extendsClause, withClause, implementsClause);
3074 declaration.name.staticElement = elementA; 3082 declaration.name.staticElement = elementA;
3075 _resolveNode(declaration, [elementA, elementB, elementC, elementD]); 3083 _resolveNode(declaration, [elementA, elementB, elementC, elementD]);
3076 expect(elementA.supertype, same(elementB.type)); 3084 expect(elementA.supertype, same(elementB.type));
3077 List<InterfaceType> mixins = elementA.mixins; 3085 List<InterfaceType> mixins = elementA.mixins;
3078 expect(mixins, hasLength(1)); 3086 expect(mixins, hasLength(1));
3079 expect(mixins[0], same(elementC.type)); 3087 expect(mixins[0], same(elementC.type));
3080 List<InterfaceType> interfaces = elementA.interfaces; 3088 List<InterfaceType> interfaces = elementA.interfaces;
3081 expect(interfaces, hasLength(1)); 3089 expect(interfaces, hasLength(1));
3082 expect(interfaces[0], same(elementD.type)); 3090 expect(interfaces[0], same(elementD.type));
3083 _listener.assertNoErrors(); 3091 _listener.assertNoErrors();
3084 } 3092 }
3085 3093
3086 void test_visitClassDeclaration_instanceMemberCollidesWithClass() { 3094 test_visitClassDeclaration_instanceMemberCollidesWithClass() async {
3087 // class A {} 3095 // class A {}
3088 // class B extends A { 3096 // class B extends A {
3089 // void A() {} 3097 // void A() {}
3090 // } 3098 // }
3091 ClassElementImpl elementA = ElementFactory.classElement2("A"); 3099 ClassElementImpl elementA = ElementFactory.classElement2("A");
3092 ClassElementImpl elementB = ElementFactory.classElement2("B"); 3100 ClassElementImpl elementB = ElementFactory.classElement2("B");
3093 elementB.methods = <MethodElement>[ 3101 elementB.methods = <MethodElement>[
3094 ElementFactory.methodElement("A", VoidTypeImpl.instance) 3102 ElementFactory.methodElement("A", VoidTypeImpl.instance)
3095 ]; 3103 ];
3096 ExtendsClause extendsClause = 3104 ExtendsClause extendsClause =
3097 AstTestFactory.extendsClause(AstTestFactory.typeName(elementA)); 3105 AstTestFactory.extendsClause(AstTestFactory.typeName(elementA));
3098 ClassDeclaration declaration = AstTestFactory.classDeclaration( 3106 ClassDeclaration declaration = AstTestFactory.classDeclaration(
3099 null, "B", null, extendsClause, null, null); 3107 null, "B", null, extendsClause, null, null);
3100 declaration.name.staticElement = elementB; 3108 declaration.name.staticElement = elementB;
3101 _resolveNode(declaration, [elementA, elementB]); 3109 _resolveNode(declaration, [elementA, elementB]);
3102 expect(elementB.supertype, same(elementA.type)); 3110 expect(elementB.supertype, same(elementA.type));
3103 _listener.assertNoErrors(); 3111 _listener.assertNoErrors();
3104 } 3112 }
3105 3113
3106 void test_visitClassTypeAlias() { 3114 test_visitClassTypeAlias() async {
3107 // class A = B with C implements D; 3115 // class A = B with C implements D;
3108 ClassElement elementA = ElementFactory.classElement2("A"); 3116 ClassElement elementA = ElementFactory.classElement2("A");
3109 ClassElement elementB = ElementFactory.classElement2("B"); 3117 ClassElement elementB = ElementFactory.classElement2("B");
3110 ClassElement elementC = ElementFactory.classElement2("C"); 3118 ClassElement elementC = ElementFactory.classElement2("C");
3111 ClassElement elementD = ElementFactory.classElement2("D"); 3119 ClassElement elementD = ElementFactory.classElement2("D");
3112 WithClause withClause = 3120 WithClause withClause =
3113 AstTestFactory.withClause([AstTestFactory.typeName(elementC)]); 3121 AstTestFactory.withClause([AstTestFactory.typeName(elementC)]);
3114 ImplementsClause implementsClause = 3122 ImplementsClause implementsClause =
3115 AstTestFactory.implementsClause([AstTestFactory.typeName(elementD)]); 3123 AstTestFactory.implementsClause([AstTestFactory.typeName(elementD)]);
3116 ClassTypeAlias alias = AstTestFactory.classTypeAlias("A", null, null, 3124 ClassTypeAlias alias = AstTestFactory.classTypeAlias("A", null, null,
3117 AstTestFactory.typeName(elementB), withClause, implementsClause); 3125 AstTestFactory.typeName(elementB), withClause, implementsClause);
3118 alias.name.staticElement = elementA; 3126 alias.name.staticElement = elementA;
3119 _resolveNode(alias, [elementA, elementB, elementC, elementD]); 3127 _resolveNode(alias, [elementA, elementB, elementC, elementD]);
3120 expect(elementA.supertype, same(elementB.type)); 3128 expect(elementA.supertype, same(elementB.type));
3121 List<InterfaceType> mixins = elementA.mixins; 3129 List<InterfaceType> mixins = elementA.mixins;
3122 expect(mixins, hasLength(1)); 3130 expect(mixins, hasLength(1));
3123 expect(mixins[0], same(elementC.type)); 3131 expect(mixins[0], same(elementC.type));
3124 List<InterfaceType> interfaces = elementA.interfaces; 3132 List<InterfaceType> interfaces = elementA.interfaces;
3125 expect(interfaces, hasLength(1)); 3133 expect(interfaces, hasLength(1));
3126 expect(interfaces[0], same(elementD.type)); 3134 expect(interfaces[0], same(elementD.type));
3127 _listener.assertNoErrors(); 3135 _listener.assertNoErrors();
3128 } 3136 }
3129 3137
3130 void test_visitClassTypeAlias_constructorWithOptionalParams_ignored() { 3138 test_visitClassTypeAlias_constructorWithOptionalParams_ignored() async {
3131 // class T {} 3139 // class T {}
3132 // class B { 3140 // class B {
3133 // B.c1(); 3141 // B.c1();
3134 // B.c2([T a0]); 3142 // B.c2([T a0]);
3135 // B.c3({T a0}); 3143 // B.c3({T a0});
3136 // } 3144 // }
3137 // class M {} 3145 // class M {}
3138 // class C = B with M 3146 // class C = B with M
3139 ClassElement classT = ElementFactory.classElement2('T', []); 3147 ClassElement classT = ElementFactory.classElement2('T', []);
3140 ClassElementImpl classB = ElementFactory.classElement2('B', []); 3148 ClassElementImpl classB = ElementFactory.classElement2('B', []);
(...skipping 20 matching lines...) Expand all
3161 ConstructorElement constructor = classC.constructors[0]; 3169 ConstructorElement constructor = classC.constructors[0];
3162 expect(constructor.isFactory, isFalse); 3170 expect(constructor.isFactory, isFalse);
3163 expect(constructor.isSynthetic, isTrue); 3171 expect(constructor.isSynthetic, isTrue);
3164 expect(constructor.name, 'c1'); 3172 expect(constructor.name, 'c1');
3165 expect(constructor.functions, hasLength(0)); 3173 expect(constructor.functions, hasLength(0));
3166 expect(constructor.labels, hasLength(0)); 3174 expect(constructor.labels, hasLength(0));
3167 expect(constructor.localVariables, hasLength(0)); 3175 expect(constructor.localVariables, hasLength(0));
3168 expect(constructor.parameters, isEmpty); 3176 expect(constructor.parameters, isEmpty);
3169 } 3177 }
3170 3178
3171 void test_visitClassTypeAlias_constructorWithParams() { 3179 test_visitClassTypeAlias_constructorWithParams() async {
3172 // class T {} 3180 // class T {}
3173 // class B { 3181 // class B {
3174 // B(T a0); 3182 // B(T a0);
3175 // } 3183 // }
3176 // class M {} 3184 // class M {}
3177 // class C = B with M 3185 // class C = B with M
3178 ClassElement classT = ElementFactory.classElement2('T', []); 3186 ClassElement classT = ElementFactory.classElement2('T', []);
3179 ClassElementImpl classB = ElementFactory.classElement2('B', []); 3187 ClassElementImpl classB = ElementFactory.classElement2('B', []);
3180 ConstructorElementImpl constructorB = 3188 ConstructorElementImpl constructorB =
3181 ElementFactory.constructorElement2(classB, '', [classT.type]); 3189 ElementFactory.constructorElement2(classB, '', [classT.type]);
(...skipping 13 matching lines...) Expand all
3195 expect(constructor.name, ''); 3203 expect(constructor.name, '');
3196 expect(constructor.functions, hasLength(0)); 3204 expect(constructor.functions, hasLength(0));
3197 expect(constructor.labels, hasLength(0)); 3205 expect(constructor.labels, hasLength(0));
3198 expect(constructor.localVariables, hasLength(0)); 3206 expect(constructor.localVariables, hasLength(0));
3199 expect(constructor.parameters, hasLength(1)); 3207 expect(constructor.parameters, hasLength(1));
3200 expect(constructor.parameters[0].type, equals(classT.type)); 3208 expect(constructor.parameters[0].type, equals(classT.type));
3201 expect(constructor.parameters[0].name, 3209 expect(constructor.parameters[0].name,
3202 equals(constructorB.parameters[0].name)); 3210 equals(constructorB.parameters[0].name));
3203 } 3211 }
3204 3212
3205 void test_visitClassTypeAlias_defaultConstructor() { 3213 test_visitClassTypeAlias_defaultConstructor() async {
3206 // class B {} 3214 // class B {}
3207 // class M {} 3215 // class M {}
3208 // class C = B with M 3216 // class C = B with M
3209 ClassElementImpl classB = ElementFactory.classElement2('B', []); 3217 ClassElementImpl classB = ElementFactory.classElement2('B', []);
3210 ConstructorElementImpl constructorB = 3218 ConstructorElementImpl constructorB =
3211 ElementFactory.constructorElement2(classB, '', []); 3219 ElementFactory.constructorElement2(classB, '', []);
3212 constructorB.setModifier(Modifier.SYNTHETIC, true); 3220 constructorB.setModifier(Modifier.SYNTHETIC, true);
3213 classB.constructors = [constructorB]; 3221 classB.constructors = [constructorB];
3214 ClassElement classM = ElementFactory.classElement2('M', []); 3222 ClassElement classM = ElementFactory.classElement2('M', []);
3215 WithClause withClause = 3223 WithClause withClause =
3216 AstTestFactory.withClause([AstTestFactory.typeName(classM, [])]); 3224 AstTestFactory.withClause([AstTestFactory.typeName(classM, [])]);
3217 ClassElement classC = ElementFactory.classTypeAlias2('C', []); 3225 ClassElement classC = ElementFactory.classTypeAlias2('C', []);
3218 ClassTypeAlias alias = AstTestFactory.classTypeAlias( 3226 ClassTypeAlias alias = AstTestFactory.classTypeAlias(
3219 'C', null, null, AstTestFactory.typeName(classB, []), withClause, null); 3227 'C', null, null, AstTestFactory.typeName(classB, []), withClause, null);
3220 alias.name.staticElement = classC; 3228 alias.name.staticElement = classC;
3221 _resolveNode(alias, [classB, classM, classC]); 3229 _resolveNode(alias, [classB, classM, classC]);
3222 expect(classC.constructors, hasLength(1)); 3230 expect(classC.constructors, hasLength(1));
3223 ConstructorElement constructor = classC.constructors[0]; 3231 ConstructorElement constructor = classC.constructors[0];
3224 expect(constructor.isFactory, isFalse); 3232 expect(constructor.isFactory, isFalse);
3225 expect(constructor.isSynthetic, isTrue); 3233 expect(constructor.isSynthetic, isTrue);
3226 expect(constructor.name, ''); 3234 expect(constructor.name, '');
3227 expect(constructor.functions, hasLength(0)); 3235 expect(constructor.functions, hasLength(0));
3228 expect(constructor.labels, hasLength(0)); 3236 expect(constructor.labels, hasLength(0));
3229 expect(constructor.localVariables, hasLength(0)); 3237 expect(constructor.localVariables, hasLength(0));
3230 expect(constructor.parameters, isEmpty); 3238 expect(constructor.parameters, isEmpty);
3231 } 3239 }
3232 3240
3233 void test_visitFieldFormalParameter_functionType() { 3241 test_visitFieldFormalParameter_functionType() async {
3234 InterfaceType intType = _typeProvider.intType; 3242 InterfaceType intType = _typeProvider.intType;
3235 TypeName intTypeName = AstTestFactory.typeName4("int"); 3243 TypeName intTypeName = AstTestFactory.typeName4("int");
3236 String innerParameterName = "a"; 3244 String innerParameterName = "a";
3237 SimpleFormalParameter parameter = 3245 SimpleFormalParameter parameter =
3238 AstTestFactory.simpleFormalParameter3(innerParameterName); 3246 AstTestFactory.simpleFormalParameter3(innerParameterName);
3239 parameter.identifier.staticElement = 3247 parameter.identifier.staticElement =
3240 ElementFactory.requiredParameter(innerParameterName); 3248 ElementFactory.requiredParameter(innerParameterName);
3241 String outerParameterName = "p"; 3249 String outerParameterName = "p";
3242 FormalParameter node = AstTestFactory.fieldFormalParameter( 3250 FormalParameter node = AstTestFactory.fieldFormalParameter(
3243 null, 3251 null,
3244 intTypeName, 3252 intTypeName,
3245 outerParameterName, 3253 outerParameterName,
3246 AstTestFactory.formalParameterList([parameter])); 3254 AstTestFactory.formalParameterList([parameter]));
3247 node.identifier.staticElement = 3255 node.identifier.staticElement =
3248 ElementFactory.requiredParameter(outerParameterName); 3256 ElementFactory.requiredParameter(outerParameterName);
3249 DartType parameterType = _resolveFormalParameter(node, [intType.element]); 3257 DartType parameterType = _resolveFormalParameter(node, [intType.element]);
3250 EngineTestCase.assertInstanceOf( 3258 EngineTestCase.assertInstanceOf(
3251 (obj) => obj is FunctionType, FunctionType, parameterType); 3259 (obj) => obj is FunctionType, FunctionType, parameterType);
3252 FunctionType functionType = parameterType as FunctionType; 3260 FunctionType functionType = parameterType as FunctionType;
3253 expect(functionType.returnType, same(intType)); 3261 expect(functionType.returnType, same(intType));
3254 expect(functionType.parameters, hasLength(1)); 3262 expect(functionType.parameters, hasLength(1));
3255 _listener.assertNoErrors(); 3263 _listener.assertNoErrors();
3256 } 3264 }
3257 3265
3258 void test_visitFieldFormalParameter_noType() { 3266 test_visitFieldFormalParameter_noType() async {
3259 String parameterName = "p"; 3267 String parameterName = "p";
3260 FormalParameter node = 3268 FormalParameter node =
3261 AstTestFactory.fieldFormalParameter(Keyword.VAR, null, parameterName); 3269 AstTestFactory.fieldFormalParameter(Keyword.VAR, null, parameterName);
3262 node.identifier.staticElement = 3270 node.identifier.staticElement =
3263 ElementFactory.requiredParameter(parameterName); 3271 ElementFactory.requiredParameter(parameterName);
3264 expect(_resolveFormalParameter(node), same(_typeProvider.dynamicType)); 3272 expect(_resolveFormalParameter(node), same(_typeProvider.dynamicType));
3265 _listener.assertNoErrors(); 3273 _listener.assertNoErrors();
3266 } 3274 }
3267 3275
3268 void test_visitFieldFormalParameter_type() { 3276 test_visitFieldFormalParameter_type() async {
3269 InterfaceType intType = _typeProvider.intType; 3277 InterfaceType intType = _typeProvider.intType;
3270 TypeName intTypeName = AstTestFactory.typeName4("int"); 3278 TypeName intTypeName = AstTestFactory.typeName4("int");
3271 String parameterName = "p"; 3279 String parameterName = "p";
3272 FormalParameter node = 3280 FormalParameter node =
3273 AstTestFactory.fieldFormalParameter(null, intTypeName, parameterName); 3281 AstTestFactory.fieldFormalParameter(null, intTypeName, parameterName);
3274 node.identifier.staticElement = 3282 node.identifier.staticElement =
3275 ElementFactory.requiredParameter(parameterName); 3283 ElementFactory.requiredParameter(parameterName);
3276 expect(_resolveFormalParameter(node, [intType.element]), same(intType)); 3284 expect(_resolveFormalParameter(node, [intType.element]), same(intType));
3277 _listener.assertNoErrors(); 3285 _listener.assertNoErrors();
3278 } 3286 }
3279 3287
3280 void test_visitFunctionDeclaration() { 3288 test_visitFunctionDeclaration() async {
3281 // R f(P p) {} 3289 // R f(P p) {}
3282 // class R {} 3290 // class R {}
3283 // class P {} 3291 // class P {}
3284 ClassElement elementR = ElementFactory.classElement2('R'); 3292 ClassElement elementR = ElementFactory.classElement2('R');
3285 ClassElement elementP = ElementFactory.classElement2('P'); 3293 ClassElement elementP = ElementFactory.classElement2('P');
3286 FunctionElement elementF = ElementFactory.functionElement('f'); 3294 FunctionElement elementF = ElementFactory.functionElement('f');
3287 FunctionDeclaration declaration = AstTestFactory.functionDeclaration( 3295 FunctionDeclaration declaration = AstTestFactory.functionDeclaration(
3288 AstTestFactory.typeName4('R'), 3296 AstTestFactory.typeName4('R'),
3289 null, 3297 null,
3290 'f', 3298 'f',
3291 AstTestFactory.functionExpression2( 3299 AstTestFactory.functionExpression2(
3292 AstTestFactory.formalParameterList([ 3300 AstTestFactory.formalParameterList([
3293 AstTestFactory.simpleFormalParameter4( 3301 AstTestFactory.simpleFormalParameter4(
3294 AstTestFactory.typeName4('P'), 'p') 3302 AstTestFactory.typeName4('P'), 'p')
3295 ]), 3303 ]),
3296 null)); 3304 null));
3297 declaration.name.staticElement = elementF; 3305 declaration.name.staticElement = elementF;
3298 _resolveNode(declaration, [elementR, elementP]); 3306 _resolveNode(declaration, [elementR, elementP]);
3299 expect(declaration.returnType.type, elementR.type); 3307 expect(declaration.returnType.type, elementR.type);
3300 SimpleFormalParameter parameter = 3308 SimpleFormalParameter parameter =
3301 declaration.functionExpression.parameters.parameters[0]; 3309 declaration.functionExpression.parameters.parameters[0];
3302 expect(parameter.type.type, elementP.type); 3310 expect(parameter.type.type, elementP.type);
3303 _listener.assertNoErrors(); 3311 _listener.assertNoErrors();
3304 } 3312 }
3305 3313
3306 void test_visitFunctionDeclaration_typeParameter() { 3314 test_visitFunctionDeclaration_typeParameter() async {
3307 // E f<E>(E e) {} 3315 // E f<E>(E e) {}
3308 TypeParameterElement elementE = ElementFactory.typeParameterElement('E'); 3316 TypeParameterElement elementE = ElementFactory.typeParameterElement('E');
3309 FunctionElementImpl elementF = ElementFactory.functionElement('f'); 3317 FunctionElementImpl elementF = ElementFactory.functionElement('f');
3310 elementF.typeParameters = <TypeParameterElement>[elementE]; 3318 elementF.typeParameters = <TypeParameterElement>[elementE];
3311 FunctionDeclaration declaration = AstTestFactory.functionDeclaration( 3319 FunctionDeclaration declaration = AstTestFactory.functionDeclaration(
3312 AstTestFactory.typeName4('E'), 3320 AstTestFactory.typeName4('E'),
3313 null, 3321 null,
3314 'f', 3322 'f',
3315 AstTestFactory.functionExpression2( 3323 AstTestFactory.functionExpression2(
3316 AstTestFactory.formalParameterList([ 3324 AstTestFactory.formalParameterList([
3317 AstTestFactory.simpleFormalParameter4( 3325 AstTestFactory.simpleFormalParameter4(
3318 AstTestFactory.typeName4('E'), 'e') 3326 AstTestFactory.typeName4('E'), 'e')
3319 ]), 3327 ]),
3320 null)); 3328 null));
3321 declaration.name.staticElement = elementF; 3329 declaration.name.staticElement = elementF;
3322 _resolveNode(declaration, []); 3330 _resolveNode(declaration, []);
3323 expect(declaration.returnType.type, elementE.type); 3331 expect(declaration.returnType.type, elementE.type);
3324 SimpleFormalParameter parameter = 3332 SimpleFormalParameter parameter =
3325 declaration.functionExpression.parameters.parameters[0]; 3333 declaration.functionExpression.parameters.parameters[0];
3326 expect(parameter.type.type, elementE.type); 3334 expect(parameter.type.type, elementE.type);
3327 _listener.assertNoErrors(); 3335 _listener.assertNoErrors();
3328 } 3336 }
3329 3337
3330 void test_visitFunctionTypedFormalParameter() { 3338 test_visitFunctionTypedFormalParameter() async {
3331 // R f(R g(P p)) {} 3339 // R f(R g(P p)) {}
3332 // class R {} 3340 // class R {}
3333 // class P {} 3341 // class P {}
3334 ClassElement elementR = ElementFactory.classElement2('R'); 3342 ClassElement elementR = ElementFactory.classElement2('R');
3335 ClassElement elementP = ElementFactory.classElement2('P'); 3343 ClassElement elementP = ElementFactory.classElement2('P');
3336 FunctionElement elementF = ElementFactory.functionElement('f'); 3344 FunctionElement elementF = ElementFactory.functionElement('f');
3337 ParameterElementImpl requiredParameter = 3345 ParameterElementImpl requiredParameter =
3338 ElementFactory.requiredParameter('p'); 3346 ElementFactory.requiredParameter('p');
3339 FunctionTypedFormalParameter parameterDeclaration = AstTestFactory 3347 FunctionTypedFormalParameter parameterDeclaration = AstTestFactory
3340 .functionTypedFormalParameter(AstTestFactory.typeName4('R'), 'g', [ 3348 .functionTypedFormalParameter(AstTestFactory.typeName4('R'), 'g', [
(...skipping 10 matching lines...) Expand all
3351 _resolveNode(declaration, [elementR, elementP]); 3359 _resolveNode(declaration, [elementR, elementP]);
3352 expect(declaration.returnType.type, elementR.type); 3360 expect(declaration.returnType.type, elementR.type);
3353 FunctionTypedFormalParameter parameter = 3361 FunctionTypedFormalParameter parameter =
3354 declaration.functionExpression.parameters.parameters[0]; 3362 declaration.functionExpression.parameters.parameters[0];
3355 expect(parameter.returnType.type, elementR.type); 3363 expect(parameter.returnType.type, elementR.type);
3356 SimpleFormalParameter innerParameter = parameter.parameters.parameters[0]; 3364 SimpleFormalParameter innerParameter = parameter.parameters.parameters[0];
3357 expect(innerParameter.type.type, elementP.type); 3365 expect(innerParameter.type.type, elementP.type);
3358 _listener.assertNoErrors(); 3366 _listener.assertNoErrors();
3359 } 3367 }
3360 3368
3361 void test_visitFunctionTypedFormalParameter_typeParameter() { 3369 test_visitFunctionTypedFormalParameter_typeParameter() async {
3362 // R f(R g<E>(E e)) {} 3370 // R f(R g<E>(E e)) {}
3363 // class R {} 3371 // class R {}
3364 ClassElement elementR = ElementFactory.classElement2('R'); 3372 ClassElement elementR = ElementFactory.classElement2('R');
3365 TypeParameterElement elementE = ElementFactory.typeParameterElement('E'); 3373 TypeParameterElement elementE = ElementFactory.typeParameterElement('E');
3366 FunctionElement elementF = ElementFactory.functionElement('f'); 3374 FunctionElement elementF = ElementFactory.functionElement('f');
3367 ParameterElementImpl requiredParameter = 3375 ParameterElementImpl requiredParameter =
3368 ElementFactory.requiredParameter('g'); 3376 ElementFactory.requiredParameter('g');
3369 requiredParameter.typeParameters = <TypeParameterElement>[elementE]; 3377 requiredParameter.typeParameters = <TypeParameterElement>[elementE];
3370 FunctionTypedFormalParameter parameterDeclaration = AstTestFactory 3378 FunctionTypedFormalParameter parameterDeclaration = AstTestFactory
3371 .functionTypedFormalParameter(AstTestFactory.typeName4('R'), 'g', [ 3379 .functionTypedFormalParameter(AstTestFactory.typeName4('R'), 'g', [
(...skipping 10 matching lines...) Expand all
3382 _resolveNode(declaration, [elementR]); 3390 _resolveNode(declaration, [elementR]);
3383 expect(declaration.returnType.type, elementR.type); 3391 expect(declaration.returnType.type, elementR.type);
3384 FunctionTypedFormalParameter parameter = 3392 FunctionTypedFormalParameter parameter =
3385 declaration.functionExpression.parameters.parameters[0]; 3393 declaration.functionExpression.parameters.parameters[0];
3386 expect(parameter.returnType.type, elementR.type); 3394 expect(parameter.returnType.type, elementR.type);
3387 SimpleFormalParameter innerParameter = parameter.parameters.parameters[0]; 3395 SimpleFormalParameter innerParameter = parameter.parameters.parameters[0];
3388 expect(innerParameter.type.type, elementE.type); 3396 expect(innerParameter.type.type, elementE.type);
3389 _listener.assertNoErrors(); 3397 _listener.assertNoErrors();
3390 } 3398 }
3391 3399
3392 void test_visitMethodDeclaration() { 3400 test_visitMethodDeclaration() async {
3393 // class A { 3401 // class A {
3394 // R m(P p) {} 3402 // R m(P p) {}
3395 // } 3403 // }
3396 // class R {} 3404 // class R {}
3397 // class P {} 3405 // class P {}
3398 ClassElementImpl elementA = ElementFactory.classElement2('A'); 3406 ClassElementImpl elementA = ElementFactory.classElement2('A');
3399 ClassElement elementR = ElementFactory.classElement2('R'); 3407 ClassElement elementR = ElementFactory.classElement2('R');
3400 ClassElement elementP = ElementFactory.classElement2('P'); 3408 ClassElement elementP = ElementFactory.classElement2('P');
3401 MethodElement elementM = ElementFactory.methodElement('m', null); 3409 MethodElement elementM = ElementFactory.methodElement('m', null);
3402 elementA.methods = <MethodElement>[elementM]; 3410 elementA.methods = <MethodElement>[elementM];
3403 MethodDeclaration declaration = AstTestFactory.methodDeclaration( 3411 MethodDeclaration declaration = AstTestFactory.methodDeclaration(
3404 null, 3412 null,
3405 AstTestFactory.typeName4('R'), 3413 AstTestFactory.typeName4('R'),
3406 null, 3414 null,
3407 null, 3415 null,
3408 AstTestFactory.identifier3('m'), 3416 AstTestFactory.identifier3('m'),
3409 AstTestFactory.formalParameterList([ 3417 AstTestFactory.formalParameterList([
3410 AstTestFactory.simpleFormalParameter4( 3418 AstTestFactory.simpleFormalParameter4(
3411 AstTestFactory.typeName4('P'), 'p') 3419 AstTestFactory.typeName4('P'), 'p')
3412 ])); 3420 ]));
3413 declaration.name.staticElement = elementM; 3421 declaration.name.staticElement = elementM;
3414 _resolveNode(declaration, [elementA, elementR, elementP]); 3422 _resolveNode(declaration, [elementA, elementR, elementP]);
3415 expect(declaration.returnType.type, elementR.type); 3423 expect(declaration.returnType.type, elementR.type);
3416 SimpleFormalParameter parameter = declaration.parameters.parameters[0]; 3424 SimpleFormalParameter parameter = declaration.parameters.parameters[0];
3417 expect(parameter.type.type, elementP.type); 3425 expect(parameter.type.type, elementP.type);
3418 _listener.assertNoErrors(); 3426 _listener.assertNoErrors();
3419 } 3427 }
3420 3428
3421 void test_visitMethodDeclaration_typeParameter() { 3429 test_visitMethodDeclaration_typeParameter() async {
3422 // class A { 3430 // class A {
3423 // E m<E>(E e) {} 3431 // E m<E>(E e) {}
3424 // } 3432 // }
3425 ClassElementImpl elementA = ElementFactory.classElement2('A'); 3433 ClassElementImpl elementA = ElementFactory.classElement2('A');
3426 TypeParameterElement elementE = ElementFactory.typeParameterElement('E'); 3434 TypeParameterElement elementE = ElementFactory.typeParameterElement('E');
3427 MethodElementImpl elementM = ElementFactory.methodElement('m', null); 3435 MethodElementImpl elementM = ElementFactory.methodElement('m', null);
3428 elementM.typeParameters = <TypeParameterElement>[elementE]; 3436 elementM.typeParameters = <TypeParameterElement>[elementE];
3429 elementA.methods = <MethodElement>[elementM]; 3437 elementA.methods = <MethodElement>[elementM];
3430 MethodDeclaration declaration = AstTestFactory.methodDeclaration( 3438 MethodDeclaration declaration = AstTestFactory.methodDeclaration(
3431 null, 3439 null,
3432 AstTestFactory.typeName4('E'), 3440 AstTestFactory.typeName4('E'),
3433 null, 3441 null,
3434 null, 3442 null,
3435 AstTestFactory.identifier3('m'), 3443 AstTestFactory.identifier3('m'),
3436 AstTestFactory.formalParameterList([ 3444 AstTestFactory.formalParameterList([
3437 AstTestFactory.simpleFormalParameter4( 3445 AstTestFactory.simpleFormalParameter4(
3438 AstTestFactory.typeName4('E'), 'e') 3446 AstTestFactory.typeName4('E'), 'e')
3439 ])); 3447 ]));
3440 declaration.name.staticElement = elementM; 3448 declaration.name.staticElement = elementM;
3441 _resolveNode(declaration, [elementA]); 3449 _resolveNode(declaration, [elementA]);
3442 expect(declaration.returnType.type, elementE.type); 3450 expect(declaration.returnType.type, elementE.type);
3443 SimpleFormalParameter parameter = declaration.parameters.parameters[0]; 3451 SimpleFormalParameter parameter = declaration.parameters.parameters[0];
3444 expect(parameter.type.type, elementE.type); 3452 expect(parameter.type.type, elementE.type);
3445 _listener.assertNoErrors(); 3453 _listener.assertNoErrors();
3446 } 3454 }
3447 3455
3448 void test_visitSimpleFormalParameter_noType() { 3456 test_visitSimpleFormalParameter_noType() async {
3449 // p 3457 // p
3450 FormalParameter node = AstTestFactory.simpleFormalParameter3("p"); 3458 FormalParameter node = AstTestFactory.simpleFormalParameter3("p");
3451 node.identifier.staticElement = 3459 node.identifier.staticElement =
3452 new ParameterElementImpl.forNode(AstTestFactory.identifier3("p")); 3460 new ParameterElementImpl.forNode(AstTestFactory.identifier3("p"));
3453 expect(_resolveFormalParameter(node), same(_typeProvider.dynamicType)); 3461 expect(_resolveFormalParameter(node), same(_typeProvider.dynamicType));
3454 _listener.assertNoErrors(); 3462 _listener.assertNoErrors();
3455 } 3463 }
3456 3464
3457 void test_visitSimpleFormalParameter_type() { 3465 test_visitSimpleFormalParameter_type() async {
3458 // int p 3466 // int p
3459 InterfaceType intType = _typeProvider.intType; 3467 InterfaceType intType = _typeProvider.intType;
3460 ClassElement intElement = intType.element; 3468 ClassElement intElement = intType.element;
3461 FormalParameter node = AstTestFactory.simpleFormalParameter4( 3469 FormalParameter node = AstTestFactory.simpleFormalParameter4(
3462 AstTestFactory.typeName(intElement), "p"); 3470 AstTestFactory.typeName(intElement), "p");
3463 SimpleIdentifier identifier = node.identifier; 3471 SimpleIdentifier identifier = node.identifier;
3464 ParameterElementImpl element = new ParameterElementImpl.forNode(identifier); 3472 ParameterElementImpl element = new ParameterElementImpl.forNode(identifier);
3465 identifier.staticElement = element; 3473 identifier.staticElement = element;
3466 expect(_resolveFormalParameter(node, [intElement]), same(intType)); 3474 expect(_resolveFormalParameter(node, [intElement]), same(intType));
3467 _listener.assertNoErrors(); 3475 _listener.assertNoErrors();
3468 } 3476 }
3469 3477
3470 void test_visitTypeName_noParameters_noArguments() { 3478 test_visitTypeName_noParameters_noArguments() async {
3471 ClassElement classA = ElementFactory.classElement2("A"); 3479 ClassElement classA = ElementFactory.classElement2("A");
3472 TypeName typeName = AstTestFactory.typeName(classA); 3480 TypeName typeName = AstTestFactory.typeName(classA);
3473 typeName.type = null; 3481 typeName.type = null;
3474 _resolveNode(typeName, [classA]); 3482 _resolveNode(typeName, [classA]);
3475 expect(typeName.type, same(classA.type)); 3483 expect(typeName.type, same(classA.type));
3476 _listener.assertNoErrors(); 3484 _listener.assertNoErrors();
3477 } 3485 }
3478 3486
3479 void test_visitTypeName_noParameters_noArguments_undefined() { 3487 test_visitTypeName_noParameters_noArguments_undefined() async {
3480 SimpleIdentifier id = AstTestFactory.identifier3("unknown") 3488 SimpleIdentifier id = AstTestFactory.identifier3("unknown")
3481 ..staticElement = new _StaleElement(); 3489 ..staticElement = new _StaleElement();
3482 TypeName typeName = astFactory.typeName(id, null); 3490 TypeName typeName = astFactory.typeName(id, null);
3483 _resolveNode(typeName, []); 3491 _resolveNode(typeName, []);
3484 expect(typeName.type, UndefinedTypeImpl.instance); 3492 expect(typeName.type, UndefinedTypeImpl.instance);
3485 expect(typeName.name.staticElement, null); 3493 expect(typeName.name.staticElement, null);
3486 _listener.assertErrorsWithCodes([StaticWarningCode.UNDEFINED_CLASS]); 3494 _listener.assertErrorsWithCodes([StaticWarningCode.UNDEFINED_CLASS]);
3487 } 3495 }
3488 3496
3489 void test_visitTypeName_parameters_arguments() { 3497 test_visitTypeName_parameters_arguments() async {
3490 ClassElement classA = ElementFactory.classElement2("A", ["E"]); 3498 ClassElement classA = ElementFactory.classElement2("A", ["E"]);
3491 ClassElement classB = ElementFactory.classElement2("B"); 3499 ClassElement classB = ElementFactory.classElement2("B");
3492 TypeName typeName = 3500 TypeName typeName =
3493 AstTestFactory.typeName(classA, [AstTestFactory.typeName(classB)]); 3501 AstTestFactory.typeName(classA, [AstTestFactory.typeName(classB)]);
3494 typeName.type = null; 3502 typeName.type = null;
3495 _resolveNode(typeName, [classA, classB]); 3503 _resolveNode(typeName, [classA, classB]);
3496 InterfaceType resultType = typeName.type as InterfaceType; 3504 InterfaceType resultType = typeName.type as InterfaceType;
3497 expect(resultType.element, same(classA)); 3505 expect(resultType.element, same(classA));
3498 List<DartType> resultArguments = resultType.typeArguments; 3506 List<DartType> resultArguments = resultType.typeArguments;
3499 expect(resultArguments, hasLength(1)); 3507 expect(resultArguments, hasLength(1));
3500 expect(resultArguments[0], same(classB.type)); 3508 expect(resultArguments[0], same(classB.type));
3501 _listener.assertNoErrors(); 3509 _listener.assertNoErrors();
3502 } 3510 }
3503 3511
3504 void test_visitTypeName_parameters_noArguments() { 3512 test_visitTypeName_parameters_noArguments() async {
3505 ClassElement classA = ElementFactory.classElement2("A", ["E"]); 3513 ClassElement classA = ElementFactory.classElement2("A", ["E"]);
3506 TypeName typeName = AstTestFactory.typeName(classA); 3514 TypeName typeName = AstTestFactory.typeName(classA);
3507 typeName.type = null; 3515 typeName.type = null;
3508 _resolveNode(typeName, [classA]); 3516 _resolveNode(typeName, [classA]);
3509 InterfaceType resultType = typeName.type as InterfaceType; 3517 InterfaceType resultType = typeName.type as InterfaceType;
3510 expect(resultType.element, same(classA)); 3518 expect(resultType.element, same(classA));
3511 List<DartType> resultArguments = resultType.typeArguments; 3519 List<DartType> resultArguments = resultType.typeArguments;
3512 expect(resultArguments, hasLength(1)); 3520 expect(resultArguments, hasLength(1));
3513 expect(resultArguments[0], same(DynamicTypeImpl.instance)); 3521 expect(resultArguments[0], same(DynamicTypeImpl.instance));
3514 _listener.assertNoErrors(); 3522 _listener.assertNoErrors();
3515 } 3523 }
3516 3524
3517 void test_visitTypeName_prefixed_noParameters_noArguments_undefined() { 3525 test_visitTypeName_prefixed_noParameters_noArguments_undefined() async {
3518 SimpleIdentifier prefix = AstTestFactory.identifier3("unknownPrefix") 3526 SimpleIdentifier prefix = AstTestFactory.identifier3("unknownPrefix")
3519 ..staticElement = new _StaleElement(); 3527 ..staticElement = new _StaleElement();
3520 SimpleIdentifier suffix = AstTestFactory.identifier3("unknownSuffix") 3528 SimpleIdentifier suffix = AstTestFactory.identifier3("unknownSuffix")
3521 ..staticElement = new _StaleElement(); 3529 ..staticElement = new _StaleElement();
3522 TypeName typeName = 3530 TypeName typeName =
3523 astFactory.typeName(AstTestFactory.identifier(prefix, suffix), null); 3531 astFactory.typeName(AstTestFactory.identifier(prefix, suffix), null);
3524 _resolveNode(typeName, []); 3532 _resolveNode(typeName, []);
3525 expect(typeName.type, UndefinedTypeImpl.instance); 3533 expect(typeName.type, UndefinedTypeImpl.instance);
3526 expect(prefix.staticElement, null); 3534 expect(prefix.staticElement, null);
3527 expect(suffix.staticElement, null); 3535 expect(suffix.staticElement, null);
3528 _listener.assertErrorsWithCodes([StaticWarningCode.UNDEFINED_CLASS]); 3536 _listener.assertErrorsWithCodes([StaticWarningCode.UNDEFINED_CLASS]);
3529 } 3537 }
3530 3538
3531 void test_visitTypeName_void() { 3539 test_visitTypeName_void() async {
3532 ClassElement classA = ElementFactory.classElement2("A"); 3540 ClassElement classA = ElementFactory.classElement2("A");
3533 TypeName typeName = AstTestFactory.typeName4("void"); 3541 TypeName typeName = AstTestFactory.typeName4("void");
3534 _resolveNode(typeName, [classA]); 3542 _resolveNode(typeName, [classA]);
3535 expect(typeName.type, same(VoidTypeImpl.instance)); 3543 expect(typeName.type, same(VoidTypeImpl.instance));
3536 _listener.assertNoErrors(); 3544 _listener.assertNoErrors();
3537 } 3545 }
3538 3546
3539 /** 3547 /**
3540 * Analyze the given catch clause and assert that the types of the parameters have been set to the 3548 * Analyze the given catch clause and assert that the types of the parameters have been set to the
3541 * given types. The types can be null if the catch clause does not have the co rresponding 3549 * given types. The types can be null if the catch clause does not have the co rresponding
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
3650 */ 3658 */
3651 class _StaleElement extends ElementImpl { 3659 class _StaleElement extends ElementImpl {
3652 _StaleElement() : super("_StaleElement", -1); 3660 _StaleElement() : super("_StaleElement", -1);
3653 3661
3654 @override 3662 @override
3655 get kind => throw "_StaleElement's kind shouldn't be accessed"; 3663 get kind => throw "_StaleElement's kind shouldn't be accessed";
3656 3664
3657 @override 3665 @override
3658 /*=T*/ accept/*<T>*/(_) => throw "_StaleElement shouldn't be visited"; 3666 /*=T*/ accept/*<T>*/(_) => throw "_StaleElement shouldn't be visited";
3659 } 3667 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698