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

Side by Side Diff: pkg/analyzer/test/src/task/dart_test.dart

Issue 1462133005: Downwards inference. This adds support to the resolver for downwards (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Minor fixes Created 5 years, 1 month 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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 test.src.task.dart_test; 5 library test.src.task.dart_test;
6 6
7 import 'package:analyzer/src/context/cache.dart'; 7 import 'package:analyzer/src/context/cache.dart';
8 import 'package:analyzer/src/generated/ast.dart'; 8 import 'package:analyzer/src/generated/ast.dart';
9 import 'package:analyzer/src/generated/constant.dart'; 9 import 'package:analyzer/src/generated/constant.dart';
10 import 'package:analyzer/src/generated/element.dart'; 10 import 'package:analyzer/src/generated/element.dart';
(...skipping 1813 matching lines...) Expand 10 before | Expand all | Expand 10 after
1824 computeResult(part, DART_ERRORS, matcher: isDartErrorsTask); 1824 computeResult(part, DART_ERRORS, matcher: isDartErrorsTask);
1825 expect(outputs, hasLength(1)); 1825 expect(outputs, hasLength(1));
1826 List<AnalysisError> errors = outputs[DART_ERRORS]; 1826 List<AnalysisError> errors = outputs[DART_ERRORS];
1827 // This should contain only the errors in the part file, not the ones in the 1827 // This should contain only the errors in the part file, not the ones in the
1828 // library. 1828 // library.
1829 expect(errors, hasLength(1)); 1829 expect(errors, hasLength(1));
1830 } 1830 }
1831 } 1831 }
1832 1832
1833 @reflectiveTest 1833 @reflectiveTest
1834 class ErrorFilterTest extends _AbstractDartTaskTest {
1835 @override
1836 setUp() {
1837 super.setUp();
1838 context.setConfigurationData(CONFIGURED_ERROR_FILTERS, [
1839 (AnalysisError error) => error.errorCode.name == 'INVALID_ASSIGNMENT'
1840 ]);
1841 }
1842
1843 test_error_filters() {
1844 AnalysisTarget library = newSource(
1845 '/test.dart',
1846 '''
1847 main() {
1848 int x = ""; // INVALID_ASSIGNMENT (suppressed)
1849 // UNUSED_LOCAL_VARIABLE
1850 }''');
1851 computeResult(library, DART_ERRORS, matcher: isDartErrorsTask);
1852 expect(outputs, hasLength(1));
1853 List<AnalysisError> errors = outputs[DART_ERRORS];
1854 expect(errors, hasLength(1));
1855 expect(errors.first.errorCode, HintCode.UNUSED_LOCAL_VARIABLE);
1856 }
1857 }
1858
1859 @reflectiveTest
1834 class EvaluateUnitConstantsTaskTest extends _AbstractDartTaskTest { 1860 class EvaluateUnitConstantsTaskTest extends _AbstractDartTaskTest {
1835 test_perform() { 1861 test_perform() {
1836 Source source = newSource( 1862 Source source = newSource(
1837 '/test.dart', 1863 '/test.dart',
1838 ''' 1864 '''
1839 class C { 1865 class C {
1840 const C(); 1866 const C();
1841 } 1867 }
1842 1868
1843 @x 1869 @x
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
2234 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); 2260 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
2235 computeResult(target, HINTS, matcher: isGenerateHintsTask); 2261 computeResult(target, HINTS, matcher: isGenerateHintsTask);
2236 // validate 2262 // validate
2237 _fillErrorListener(HINTS); 2263 _fillErrorListener(HINTS);
2238 errorListener.assertErrorsWithCodes( 2264 errorListener.assertErrorsWithCodes(
2239 <ErrorCode>[HintCode.UNUSED_ELEMENT, HintCode.UNUSED_ELEMENT]); 2265 <ErrorCode>[HintCode.UNUSED_ELEMENT, HintCode.UNUSED_ELEMENT]);
2240 } 2266 }
2241 } 2267 }
2242 2268
2243 @reflectiveTest 2269 @reflectiveTest
2244 class ErrorFilterTest extends _AbstractDartTaskTest {
2245 @override
2246 setUp() {
2247 super.setUp();
2248 context.setConfigurationData(CONFIGURED_ERROR_FILTERS, [
2249 (AnalysisError error) => error.errorCode.name == 'INVALID_ASSIGNMENT'
2250 ]);
2251 }
2252
2253 test_error_filters() {
2254 AnalysisTarget library = newSource('/test.dart', '''
2255 main() {
2256 int x = ""; // INVALID_ASSIGNMENT (suppressed)
2257 // UNUSED_LOCAL_VARIABLE
2258 }''');
2259 computeResult(library, DART_ERRORS, matcher: isDartErrorsTask);
2260 expect(outputs, hasLength(1));
2261 List<AnalysisError> errors = outputs[DART_ERRORS];
2262 expect(errors, hasLength(1));
2263 expect(errors.first.errorCode, HintCode.UNUSED_LOCAL_VARIABLE);
2264 }
2265 }
2266
2267 @reflectiveTest
2268 class GenerateLintsTaskTest extends _AbstractDartTaskTest { 2270 class GenerateLintsTaskTest extends _AbstractDartTaskTest {
2269 void enableLints() { 2271 void enableLints() {
2270 AnalysisOptionsImpl options = context.analysisOptions; 2272 AnalysisOptionsImpl options = context.analysisOptions;
2271 options.lint = true; 2273 options.lint = true;
2272 context.analysisOptions = options; 2274 context.analysisOptions = options;
2273 } 2275 }
2274 2276
2275 @override 2277 @override
2276 void setUp() { 2278 void setUp() {
2277 super.setUp(); 2279 super.setUp();
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
2333 var f; 2335 var f;
2334 m(x) {} 2336 m(x) {}
2335 } 2337 }
2336 class X {} 2338 class X {}
2337 class Y {} 2339 class Y {}
2338 class Z {} 2340 class Z {}
2339 '''); 2341 ''');
2340 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT8, 2342 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT8,
2341 matcher: isInferInstanceMembersInUnitTask); 2343 matcher: isInferInstanceMembersInUnitTask);
2342 CompilationUnit unit = outputs[RESOLVED_UNIT8]; 2344 CompilationUnit unit = outputs[RESOLVED_UNIT8];
2343 VariableDeclaration field = getFieldInClass(unit, 'B', 'f'); 2345 VariableDeclaration field = AstFinder.getFieldInClass(unit, 'B', 'f');
2344 MethodDeclaration method = getMethodInClass(unit, 'B', 'm'); 2346 MethodDeclaration method = AstFinder.getMethodInClass(unit, 'B', 'm');
2345 DartType typeX = getClass(unit, 'X').element.type; 2347 DartType typeX = AstFinder.getClass(unit, 'X').element.type;
2346 DartType typeY = getClass(unit, 'Y').element.type; 2348 DartType typeY = AstFinder.getClass(unit, 'Y').element.type;
2347 DartType typeZ = getClass(unit, 'Z').element.type; 2349 DartType typeZ = AstFinder.getClass(unit, 'Z').element.type;
2348 2350
2349 expect(field.element.type, typeX); 2351 expect(field.element.type, typeX);
2350 expect(method.element.returnType, typeY); 2352 expect(method.element.returnType, typeY);
2351 expect(method.element.parameters[0].type, typeZ); 2353 expect(method.element.parameters[0].type, typeZ);
2352 } 2354 }
2353 2355
2354 void test_perform_cross_library_const() { 2356 void test_perform_cross_library_const() {
2355 enableStrongMode(); 2357 enableStrongMode();
2356 AnalysisTarget firstSource = newSource( 2358 AnalysisTarget firstSource = newSource(
2357 '/first.dart', 2359 '/first.dart',
(...skipping 13 matching lines...) Expand all
2371 } 2373 }
2372 '''); 2374 ''');
2373 computeResult( 2375 computeResult(
2374 new LibrarySpecificUnit(firstSource, firstSource), RESOLVED_UNIT8, 2376 new LibrarySpecificUnit(firstSource, firstSource), RESOLVED_UNIT8,
2375 matcher: isInferInstanceMembersInUnitTask); 2377 matcher: isInferInstanceMembersInUnitTask);
2376 CompilationUnit firstUnit = outputs[RESOLVED_UNIT8]; 2378 CompilationUnit firstUnit = outputs[RESOLVED_UNIT8];
2377 computeResult( 2379 computeResult(
2378 new LibrarySpecificUnit(secondSource, secondSource), RESOLVED_UNIT8); 2380 new LibrarySpecificUnit(secondSource, secondSource), RESOLVED_UNIT8);
2379 CompilationUnit secondUnit = outputs[RESOLVED_UNIT8]; 2381 CompilationUnit secondUnit = outputs[RESOLVED_UNIT8];
2380 2382
2381 VariableDeclaration variableA = getTopLevelVariable(firstUnit, 'a'); 2383 VariableDeclaration variableA =
2382 VariableDeclaration variableB = getTopLevelVariable(secondUnit, 'b'); 2384 AstFinder.getTopLevelVariable(firstUnit, 'a');
2383 VariableDeclaration variableC = getFieldInClass(secondUnit, 'M', 'c'); 2385 VariableDeclaration variableB =
2386 AstFinder.getTopLevelVariable(secondUnit, 'b');
2387 VariableDeclaration variableC =
2388 AstFinder.getFieldInClass(secondUnit, 'M', 'c');
2384 InterfaceType stringType = context.typeProvider.stringType; 2389 InterfaceType stringType = context.typeProvider.stringType;
2385 2390
2386 expect(variableA.element.type, stringType); 2391 expect(variableA.element.type, stringType);
2387 expect(variableB.element.type, stringType); 2392 expect(variableB.element.type, stringType);
2388 expect(variableB.initializer.staticType, stringType); 2393 expect(variableB.initializer.staticType, stringType);
2389 expect(variableC.element.type, stringType); 2394 expect(variableC.element.type, stringType);
2390 expect(variableC.initializer.staticType, stringType); 2395 expect(variableC.initializer.staticType, stringType);
2391 } 2396 }
2392 2397
2393 void test_perform_reresolution() { 2398 void test_perform_reresolution() {
2394 enableStrongMode(); 2399 enableStrongMode();
2395 AnalysisTarget source = newSource( 2400 AnalysisTarget source = newSource(
2396 '/test.dart', 2401 '/test.dart',
2397 ''' 2402 '''
2398 const topLevel = ''; 2403 const topLevel = '';
2399 class C { 2404 class C {
2400 String field = topLevel; 2405 String field = topLevel;
2401 } 2406 }
2402 '''); 2407 ''');
2403 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT8); 2408 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT8);
2404 CompilationUnit unit = outputs[RESOLVED_UNIT8]; 2409 CompilationUnit unit = outputs[RESOLVED_UNIT8];
2405 VariableDeclaration topLevelDecl = getTopLevelVariable(unit, 'topLevel'); 2410 VariableDeclaration topLevelDecl =
2406 VariableDeclaration fieldDecl = getFieldInClass(unit, 'C', 'field'); 2411 AstFinder.getTopLevelVariable(unit, 'topLevel');
2412 VariableDeclaration fieldDecl =
2413 AstFinder.getFieldInClass(unit, 'C', 'field');
2407 VariableElement topLevel = topLevelDecl.name.staticElement; 2414 VariableElement topLevel = topLevelDecl.name.staticElement;
2408 VariableElement field = fieldDecl.name.staticElement; 2415 VariableElement field = fieldDecl.name.staticElement;
2409 2416
2410 InterfaceType stringType = context.typeProvider.stringType; 2417 InterfaceType stringType = context.typeProvider.stringType;
2411 expect(topLevel.type, stringType); 2418 expect(topLevel.type, stringType);
2412 expect(field.type, stringType); 2419 expect(field.type, stringType);
2413 expect(fieldDecl.initializer.staticType, stringType); 2420 expect(fieldDecl.initializer.staticType, stringType);
2414 } 2421 }
2415 } 2422 }
2416 2423
2417 @reflectiveTest 2424 @reflectiveTest
2418 class InferStaticVariableTypesInUnitTaskTest extends _AbstractDartTaskTest { 2425 class InferStaticVariableTypesInUnitTaskTest extends _AbstractDartTaskTest {
2419 void test_perform_const_field() { 2426 void test_perform_const_field() {
2420 enableStrongMode(); 2427 enableStrongMode();
2421 AnalysisTarget source = newSource( 2428 AnalysisTarget source = newSource(
2422 '/test.dart', 2429 '/test.dart',
2423 ''' 2430 '''
2424 class M { 2431 class M {
2425 static const X = ""; 2432 static const X = "";
2426 } 2433 }
2427 '''); 2434 ''');
2428 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT6, 2435 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT6,
2429 matcher: isInferStaticVariableTypesInUnitTask); 2436 matcher: isInferStaticVariableTypesInUnitTask);
2430 CompilationUnit unit = outputs[RESOLVED_UNIT6]; 2437 CompilationUnit unit = outputs[RESOLVED_UNIT6];
2431 VariableDeclaration declaration = getFieldInClass(unit, 'M', 'X'); 2438 VariableDeclaration declaration = AstFinder.getFieldInClass(unit, 'M', 'X');
2432 InterfaceType stringType = context.typeProvider.stringType; 2439 InterfaceType stringType = context.typeProvider.stringType;
2433 expect(declaration.element.type, stringType); 2440 expect(declaration.element.type, stringType);
2434 } 2441 }
2435 2442
2436 void test_perform_nestedDeclarations() { 2443 void test_perform_nestedDeclarations() {
2437 enableStrongMode(); 2444 enableStrongMode();
2438 AnalysisTarget source = newSource( 2445 AnalysisTarget source = newSource(
2439 '/test.dart', 2446 '/test.dart',
2440 ''' 2447 '''
2441 var f = (int x) { 2448 var f = (int x) {
(...skipping 25 matching lines...) Expand all
2467 class M {} 2474 class M {}
2468 '''); 2475 ''');
2469 computeResult( 2476 computeResult(
2470 new LibrarySpecificUnit(firstSource, firstSource), RESOLVED_UNIT6, 2477 new LibrarySpecificUnit(firstSource, firstSource), RESOLVED_UNIT6,
2471 matcher: isInferStaticVariableTypesInUnitTask); 2478 matcher: isInferStaticVariableTypesInUnitTask);
2472 CompilationUnit firstUnit = outputs[RESOLVED_UNIT6]; 2479 CompilationUnit firstUnit = outputs[RESOLVED_UNIT6];
2473 computeResult( 2480 computeResult(
2474 new LibrarySpecificUnit(secondSource, secondSource), RESOLVED_UNIT6); 2481 new LibrarySpecificUnit(secondSource, secondSource), RESOLVED_UNIT6);
2475 CompilationUnit secondUnit = outputs[RESOLVED_UNIT6]; 2482 CompilationUnit secondUnit = outputs[RESOLVED_UNIT6];
2476 2483
2477 VariableDeclaration variableA = getTopLevelVariable(firstUnit, 'a'); 2484 VariableDeclaration variableA =
2478 VariableDeclaration variableB = getTopLevelVariable(secondUnit, 'b'); 2485 AstFinder.getTopLevelVariable(firstUnit, 'a');
2479 VariableDeclaration variableC = getTopLevelVariable(firstUnit, 'c'); 2486 VariableDeclaration variableB =
2480 ClassDeclaration classM = getClass(secondUnit, 'M'); 2487 AstFinder.getTopLevelVariable(secondUnit, 'b');
2488 VariableDeclaration variableC =
2489 AstFinder.getTopLevelVariable(firstUnit, 'c');
2490 ClassDeclaration classM = AstFinder.getClass(secondUnit, 'M');
2481 DartType typeM = classM.element.type; 2491 DartType typeM = classM.element.type;
2482 2492
2483 expect(variableA.element.type, typeM); 2493 expect(variableA.element.type, typeM);
2484 expect(variableB.element.type, typeM); 2494 expect(variableB.element.type, typeM);
2485 expect(variableB.initializer.staticType, typeM); 2495 expect(variableB.initializer.staticType, typeM);
2486 expect(variableC.element.type, typeM); 2496 expect(variableC.element.type, typeM);
2487 expect(variableC.initializer.staticType, typeM); 2497 expect(variableC.initializer.staticType, typeM);
2488 } 2498 }
2489 2499
2490 void test_perform_simple() { 2500 void test_perform_simple() {
(...skipping 26 matching lines...) Expand all
2517 void test_getDeclaration_staticField() { 2527 void test_getDeclaration_staticField() {
2518 AnalysisTarget source = newSource( 2528 AnalysisTarget source = newSource(
2519 '/test.dart', 2529 '/test.dart',
2520 ''' 2530 '''
2521 class C { 2531 class C {
2522 var field = ''; 2532 var field = '';
2523 } 2533 }
2524 '''); 2534 ''');
2525 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5); 2535 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5);
2526 CompilationUnit unit = outputs[RESOLVED_UNIT5]; 2536 CompilationUnit unit = outputs[RESOLVED_UNIT5];
2527 VariableDeclaration declaration = getFieldInClass(unit, 'C', 'field'); 2537 VariableDeclaration declaration =
2538 AstFinder.getFieldInClass(unit, 'C', 'field');
2528 VariableElement variable = declaration.name.staticElement; 2539 VariableElement variable = declaration.name.staticElement;
2529 InferStaticVariableTypeTask inferTask = 2540 InferStaticVariableTypeTask inferTask =
2530 new InferStaticVariableTypeTask(task.context, variable); 2541 new InferStaticVariableTypeTask(task.context, variable);
2531 expect(inferTask.getDeclaration(unit), declaration); 2542 expect(inferTask.getDeclaration(unit), declaration);
2532 } 2543 }
2533 2544
2534 void test_getDeclaration_topLevel() { 2545 void test_getDeclaration_topLevel() {
2535 AnalysisTarget source = newSource( 2546 AnalysisTarget source = newSource(
2536 '/test.dart', 2547 '/test.dart',
2537 ''' 2548 '''
2538 var topLevel = ''; 2549 var topLevel = '';
2539 '''); 2550 ''');
2540 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5); 2551 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5);
2541 CompilationUnit unit = outputs[RESOLVED_UNIT5]; 2552 CompilationUnit unit = outputs[RESOLVED_UNIT5];
2542 VariableDeclaration declaration = getTopLevelVariable(unit, 'topLevel'); 2553 VariableDeclaration declaration =
2554 AstFinder.getTopLevelVariable(unit, 'topLevel');
2543 VariableElement variable = declaration.name.staticElement; 2555 VariableElement variable = declaration.name.staticElement;
2544 InferStaticVariableTypeTask inferTask = 2556 InferStaticVariableTypeTask inferTask =
2545 new InferStaticVariableTypeTask(task.context, variable); 2557 new InferStaticVariableTypeTask(task.context, variable);
2546 expect(inferTask.getDeclaration(unit), declaration); 2558 expect(inferTask.getDeclaration(unit), declaration);
2547 } 2559 }
2548 2560
2549 void test_perform() { 2561 void test_perform() {
2550 enableStrongMode(); 2562 enableStrongMode();
2551 AnalysisTarget source = newSource( 2563 AnalysisTarget source = newSource(
2552 '/test3.dart', 2564 '/test3.dart',
2553 ''' 2565 '''
2554 var topLevel3 = ''; 2566 var topLevel3 = '';
2555 class C { 2567 class C {
2556 var field3 = topLevel3; 2568 var field3 = topLevel3;
2557 } 2569 }
2558 '''); 2570 ''');
2559 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5); 2571 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5);
2560 CompilationUnit unit = outputs[RESOLVED_UNIT5]; 2572 CompilationUnit unit = outputs[RESOLVED_UNIT5];
2561 VariableDeclaration topLevelDecl = getTopLevelVariable(unit, 'topLevel3'); 2573 VariableDeclaration topLevelDecl =
2562 VariableDeclaration fieldDecl = getFieldInClass(unit, 'C', 'field3'); 2574 AstFinder.getTopLevelVariable(unit, 'topLevel3');
2575 VariableDeclaration fieldDecl =
2576 AstFinder.getFieldInClass(unit, 'C', 'field3');
2563 VariableElement topLevel = topLevelDecl.name.staticElement; 2577 VariableElement topLevel = topLevelDecl.name.staticElement;
2564 VariableElement field = fieldDecl.name.staticElement; 2578 VariableElement field = fieldDecl.name.staticElement;
2565 2579
2566 computeResult(field, INFERRED_STATIC_VARIABLE, 2580 computeResult(field, INFERRED_STATIC_VARIABLE,
2567 matcher: isInferStaticVariableTypeTask); 2581 matcher: isInferStaticVariableTypeTask);
2568 InterfaceType stringType = context.typeProvider.stringType; 2582 InterfaceType stringType = context.typeProvider.stringType;
2569 expect(topLevel.type, stringType); 2583 expect(topLevel.type, stringType);
2570 expect(field.type, stringType); 2584 expect(field.type, stringType);
2571 expect(fieldDecl.initializer.staticType, stringType); 2585 expect(fieldDecl.initializer.staticType, stringType);
2572 } 2586 }
2573 2587
2574 void test_perform_const() { 2588 void test_perform_const() {
2575 enableStrongMode(); 2589 enableStrongMode();
2576 AnalysisTarget source = newSource( 2590 AnalysisTarget source = newSource(
2577 '/test.dart', 2591 '/test.dart',
2578 ''' 2592 '''
2579 const topLevel = "hello"; 2593 const topLevel = "hello";
2580 class C { 2594 class C {
2581 var field = topLevel; 2595 var field = topLevel;
2582 } 2596 }
2583 '''); 2597 ''');
2584 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5); 2598 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5);
2585 CompilationUnit unit = outputs[RESOLVED_UNIT5]; 2599 CompilationUnit unit = outputs[RESOLVED_UNIT5];
2586 VariableElement topLevel = 2600 VariableElement topLevel =
2587 getTopLevelVariable(unit, 'topLevel').name.staticElement; 2601 AstFinder.getTopLevelVariable(unit, 'topLevel').name.staticElement;
2588 VariableElement field = 2602 VariableElement field =
2589 getFieldInClass(unit, 'C', 'field').name.staticElement; 2603 AstFinder.getFieldInClass(unit, 'C', 'field').name.staticElement;
2590 2604
2591 computeResult(field, INFERRED_STATIC_VARIABLE, 2605 computeResult(field, INFERRED_STATIC_VARIABLE,
2592 matcher: isInferStaticVariableTypeTask); 2606 matcher: isInferStaticVariableTypeTask);
2593 InterfaceType stringType = context.typeProvider.stringType; 2607 InterfaceType stringType = context.typeProvider.stringType;
2594 expect(topLevel.type, stringType); 2608 expect(topLevel.type, stringType);
2595 expect(field.type, stringType); 2609 expect(field.type, stringType);
2596 } 2610 }
2597 2611
2598 void test_perform_cycle() { 2612 void test_perform_cycle() {
2599 enableStrongMode(); 2613 enableStrongMode();
2600 AnalysisTarget source = newSource( 2614 AnalysisTarget source = newSource(
2601 '/test.dart', 2615 '/test.dart',
2602 ''' 2616 '''
2603 var piFirst = true; 2617 var piFirst = true;
2604 var pi = piFirst ? 3.14 : tau / 2; 2618 var pi = piFirst ? 3.14 : tau / 2;
2605 var tau = piFirst ? pi * 2 : 6.28; 2619 var tau = piFirst ? pi * 2 : 6.28;
2606 '''); 2620 ''');
2607 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5); 2621 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5);
2608 CompilationUnit unit = outputs[RESOLVED_UNIT5]; 2622 CompilationUnit unit = outputs[RESOLVED_UNIT5];
2609 VariableElement piFirst = 2623 VariableElement piFirst =
2610 getTopLevelVariable(unit, 'piFirst').name.staticElement; 2624 AstFinder.getTopLevelVariable(unit, 'piFirst').name.staticElement;
2611 VariableElement pi = getTopLevelVariable(unit, 'pi').name.staticElement; 2625 VariableElement pi =
2612 VariableElement tau = getTopLevelVariable(unit, 'tau').name.staticElement; 2626 AstFinder.getTopLevelVariable(unit, 'pi').name.staticElement;
2627 VariableElement tau =
2628 AstFinder.getTopLevelVariable(unit, 'tau').name.staticElement;
2613 2629
2614 computeResult(piFirst, INFERRED_STATIC_VARIABLE, 2630 computeResult(piFirst, INFERRED_STATIC_VARIABLE,
2615 matcher: isInferStaticVariableTypeTask); 2631 matcher: isInferStaticVariableTypeTask);
2616 expect(piFirst.type, context.typeProvider.boolType); 2632 expect(piFirst.type, context.typeProvider.boolType);
2617 expect(pi.type.isDynamic, isTrue); 2633 expect(pi.type.isDynamic, isTrue);
2618 expect(tau.type.isDynamic, isTrue); 2634 expect(tau.type.isDynamic, isTrue);
2619 } 2635 }
2620 2636
2621 void test_perform_error() { 2637 void test_perform_error() {
2622 enableStrongMode(); 2638 enableStrongMode();
2623 AnalysisTarget source = newSource( 2639 AnalysisTarget source = newSource(
2624 '/test.dart', 2640 '/test.dart',
2625 ''' 2641 '''
2626 var a = '' / null; 2642 var a = '' / null;
2627 '''); 2643 ''');
2628 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5); 2644 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5);
2629 CompilationUnit unit = outputs[RESOLVED_UNIT5]; 2645 CompilationUnit unit = outputs[RESOLVED_UNIT5];
2630 VariableElement a = getTopLevelVariable(unit, 'a').name.staticElement; 2646 VariableElement a =
2647 AstFinder.getTopLevelVariable(unit, 'a').name.staticElement;
2631 2648
2632 computeResult(a, INFERRED_STATIC_VARIABLE, 2649 computeResult(a, INFERRED_STATIC_VARIABLE,
2633 matcher: isInferStaticVariableTypeTask); 2650 matcher: isInferStaticVariableTypeTask);
2634 expect(a.type.isDynamic, isTrue); 2651 expect(a.type.isDynamic, isTrue);
2635 } 2652 }
2636 2653
2637 void test_perform_null() { 2654 void test_perform_null() {
2638 enableStrongMode(); 2655 enableStrongMode();
2639 AnalysisTarget source = newSource( 2656 AnalysisTarget source = newSource(
2640 '/test.dart', 2657 '/test.dart',
2641 ''' 2658 '''
2642 var a = null; 2659 var a = null;
2643 '''); 2660 ''');
2644 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5); 2661 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5);
2645 CompilationUnit unit = outputs[RESOLVED_UNIT5]; 2662 CompilationUnit unit = outputs[RESOLVED_UNIT5];
2646 VariableElement a = getTopLevelVariable(unit, 'a').name.staticElement; 2663 VariableElement a =
2664 AstFinder.getTopLevelVariable(unit, 'a').name.staticElement;
2647 2665
2648 computeResult(a, INFERRED_STATIC_VARIABLE, 2666 computeResult(a, INFERRED_STATIC_VARIABLE,
2649 matcher: isInferStaticVariableTypeTask); 2667 matcher: isInferStaticVariableTypeTask);
2650 expect(a.type.isDynamic, isTrue); 2668 expect(a.type.isDynamic, isTrue);
2651 } 2669 }
2652 } 2670 }
2653 2671
2654 @reflectiveTest 2672 @reflectiveTest
2655 class LibraryErrorsReadyTaskTest extends _AbstractDartTaskTest { 2673 class LibraryErrorsReadyTaskTest extends _AbstractDartTaskTest {
2656 test_perform() { 2674 test_perform() {
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
3010 }); 3028 });
3011 InterfaceType intType = context.typeProvider.intType; 3029 InterfaceType intType = context.typeProvider.intType;
3012 DartType dynamicType = context.typeProvider.dynamicType; 3030 DartType dynamicType = context.typeProvider.dynamicType;
3013 3031
3014 computeResult( 3032 computeResult(
3015 new LibrarySpecificUnit(sources[1], sources[1]), RESOLVED_UNIT7); 3033 new LibrarySpecificUnit(sources[1], sources[1]), RESOLVED_UNIT7);
3016 CompilationUnit unit1 = outputs[RESOLVED_UNIT7]; 3034 CompilationUnit unit1 = outputs[RESOLVED_UNIT7];
3017 3035
3018 // B.b2 shoud be resolved on the rhs, but not yet inferred. 3036 // B.b2 shoud be resolved on the rhs, but not yet inferred.
3019 assertVariableDeclarationTypes( 3037 assertVariableDeclarationTypes(
3020 getFieldInClass(unit1, "B", "b2"), dynamicType, intType); 3038 AstFinder.getFieldInClass(unit1, "B", "b2"), dynamicType, intType);
3021 3039
3022 computeResult( 3040 computeResult(
3023 new LibrarySpecificUnit(sources[0], sources[0]), RESOLVED_UNIT7); 3041 new LibrarySpecificUnit(sources[0], sources[0]), RESOLVED_UNIT7);
3024 CompilationUnit unit0 = outputs[RESOLVED_UNIT7]; 3042 CompilationUnit unit0 = outputs[RESOLVED_UNIT7];
3025 3043
3026 // B.b2 should now be fully resolved and inferred. 3044 // B.b2 should now be fully resolved and inferred.
3027 assertVariableDeclarationTypes( 3045 assertVariableDeclarationTypes(
3028 getFieldInClass(unit1, "B", "b2"), intType, intType); 3046 AstFinder.getFieldInClass(unit1, "B", "b2"), intType, intType);
3029 3047
3030 // A.a2 should now be resolved on the rhs, but not yet inferred. 3048 // A.a2 should now be resolved on the rhs, but not yet inferred.
3031 assertVariableDeclarationTypes( 3049 assertVariableDeclarationTypes(
3032 getFieldInClass(unit0, "A", "a2"), dynamicType, intType); 3050 AstFinder.getFieldInClass(unit0, "A", "a2"), dynamicType, intType);
3033 3051
3034 computeResult( 3052 computeResult(
3035 new LibrarySpecificUnit(sources[2], sources[2]), RESOLVED_UNIT7); 3053 new LibrarySpecificUnit(sources[2], sources[2]), RESOLVED_UNIT7);
3036 3054
3037 // A.a2 should now be fully resolved and inferred. 3055 // A.a2 should now be fully resolved and inferred.
3038 assertVariableDeclarationTypes( 3056 assertVariableDeclarationTypes(
3039 getFieldInClass(unit0, "A", "a2"), intType, intType); 3057 AstFinder.getFieldInClass(unit0, "A", "a2"), intType, intType);
3040 3058
3041 assertVariableDeclarationTypes( 3059 assertVariableDeclarationTypes(
3042 getFieldInClass(unit1, "B", "b2"), intType, intType); 3060 AstFinder.getFieldInClass(unit1, "B", "b2"), intType, intType);
3043 } 3061 }
3044 3062
3045 // Test inference of instance fields across units 3063 // Test inference of instance fields across units
3046 void test_perform_inference_cross_unit_instance_cyclic() { 3064 void test_perform_inference_cross_unit_instance_cyclic() {
3047 List<Source> sources = newSources({ 3065 List<Source> sources = newSources({
3048 '/a.dart': ''' 3066 '/a.dart': '''
3049 import 'b.dart'; 3067 import 'b.dart';
3050 class A { 3068 class A {
3051 final a2 = new B().b2; 3069 final a2 = new B().b2;
3052 } 3070 }
(...skipping 14 matching lines...) Expand all
3067 ''' 3085 '''
3068 }); 3086 });
3069 DartType dynamicType = context.typeProvider.dynamicType; 3087 DartType dynamicType = context.typeProvider.dynamicType;
3070 3088
3071 computeResult( 3089 computeResult(
3072 new LibrarySpecificUnit(sources[0], sources[0]), RESOLVED_UNIT7); 3090 new LibrarySpecificUnit(sources[0], sources[0]), RESOLVED_UNIT7);
3073 CompilationUnit unit0 = outputs[RESOLVED_UNIT7]; 3091 CompilationUnit unit0 = outputs[RESOLVED_UNIT7];
3074 3092
3075 // A.a2 should now be resolved on the rhs, but not yet inferred. 3093 // A.a2 should now be resolved on the rhs, but not yet inferred.
3076 assertVariableDeclarationTypes( 3094 assertVariableDeclarationTypes(
3077 getFieldInClass(unit0, "A", "a2"), dynamicType, dynamicType); 3095 AstFinder.getFieldInClass(unit0, "A", "a2"), dynamicType, dynamicType);
3078 3096
3079 computeResult( 3097 computeResult(
3080 new LibrarySpecificUnit(sources[2], sources[2]), RESOLVED_UNIT7); 3098 new LibrarySpecificUnit(sources[2], sources[2]), RESOLVED_UNIT7);
3081 3099
3082 // A.a2 should now be fully resolved and inferred. 3100 // A.a2 should now be fully resolved and inferred.
3083 assertVariableDeclarationTypes( 3101 assertVariableDeclarationTypes(
3084 getFieldInClass(unit0, "A", "a2"), dynamicType, dynamicType); 3102 AstFinder.getFieldInClass(unit0, "A", "a2"), dynamicType, dynamicType);
3085 } 3103 }
3086 3104
3087 // Test inference of instance fields across units with cycles 3105 // Test inference of instance fields across units with cycles
3088 void test_perform_inference_cross_unit_static_instance() { 3106 void test_perform_inference_cross_unit_static_instance() {
3089 List<Source> sources = newSources({ 3107 List<Source> sources = newSources({
3090 '/a.dart': ''' 3108 '/a.dart': '''
3091 import 'b.dart'; 3109 import 'b.dart';
3092 class A { 3110 class A {
3093 static final a1 = B.b1; 3111 static final a1 = B.b1;
3094 final a2 = new B().b2; 3112 final a2 = new B().b2;
(...skipping 17 matching lines...) Expand all
3112 ''' 3130 '''
3113 }); 3131 });
3114 InterfaceType intType = context.typeProvider.intType; 3132 InterfaceType intType = context.typeProvider.intType;
3115 DartType dynamicType = context.typeProvider.dynamicType; 3133 DartType dynamicType = context.typeProvider.dynamicType;
3116 3134
3117 computeResult( 3135 computeResult(
3118 new LibrarySpecificUnit(sources[1], sources[1]), RESOLVED_UNIT7); 3136 new LibrarySpecificUnit(sources[1], sources[1]), RESOLVED_UNIT7);
3119 CompilationUnit unit1 = outputs[RESOLVED_UNIT7]; 3137 CompilationUnit unit1 = outputs[RESOLVED_UNIT7];
3120 3138
3121 assertVariableDeclarationTypes( 3139 assertVariableDeclarationTypes(
3122 getFieldInClass(unit1, "B", "b1"), intType, intType); 3140 AstFinder.getFieldInClass(unit1, "B", "b1"), intType, intType);
3123 assertVariableDeclarationTypes( 3141 assertVariableDeclarationTypes(
3124 getFieldInClass(unit1, "B", "b2"), dynamicType, intType); 3142 AstFinder.getFieldInClass(unit1, "B", "b2"), dynamicType, intType);
3125 3143
3126 computeResult( 3144 computeResult(
3127 new LibrarySpecificUnit(sources[0], sources[0]), RESOLVED_UNIT7); 3145 new LibrarySpecificUnit(sources[0], sources[0]), RESOLVED_UNIT7);
3128 CompilationUnit unit0 = outputs[RESOLVED_UNIT7]; 3146 CompilationUnit unit0 = outputs[RESOLVED_UNIT7];
3129 3147
3130 assertVariableDeclarationTypes( 3148 assertVariableDeclarationTypes(
3131 getFieldInClass(unit0, "A", "a1"), intType, intType); 3149 AstFinder.getFieldInClass(unit0, "A", "a1"), intType, intType);
3132 assertVariableDeclarationTypes( 3150 assertVariableDeclarationTypes(
3133 getFieldInClass(unit0, "A", "a2"), dynamicType, intType); 3151 AstFinder.getFieldInClass(unit0, "A", "a2"), dynamicType, intType);
3134 3152
3135 assertVariableDeclarationTypes( 3153 assertVariableDeclarationTypes(
3136 getFieldInClass(unit1, "B", "b1"), intType, intType); 3154 AstFinder.getFieldInClass(unit1, "B", "b1"), intType, intType);
3137 assertVariableDeclarationTypes( 3155 assertVariableDeclarationTypes(
3138 getFieldInClass(unit1, "B", "b2"), intType, intType); 3156 AstFinder.getFieldInClass(unit1, "B", "b2"), intType, intType);
3139 3157
3140 computeResult( 3158 computeResult(
3141 new LibrarySpecificUnit(sources[2], sources[2]), RESOLVED_UNIT7); 3159 new LibrarySpecificUnit(sources[2], sources[2]), RESOLVED_UNIT7);
3142 3160
3143 assertVariableDeclarationTypes( 3161 assertVariableDeclarationTypes(
3144 getFieldInClass(unit0, "A", "a1"), intType, intType); 3162 AstFinder.getFieldInClass(unit0, "A", "a1"), intType, intType);
3145 assertVariableDeclarationTypes( 3163 assertVariableDeclarationTypes(
3146 getFieldInClass(unit0, "A", "a2"), intType, intType); 3164 AstFinder.getFieldInClass(unit0, "A", "a2"), intType, intType);
3147 3165
3148 assertVariableDeclarationTypes( 3166 assertVariableDeclarationTypes(
3149 getFieldInClass(unit1, "B", "b1"), intType, intType); 3167 AstFinder.getFieldInClass(unit1, "B", "b1"), intType, intType);
3150 assertVariableDeclarationTypes( 3168 assertVariableDeclarationTypes(
3151 getFieldInClass(unit1, "B", "b2"), intType, intType); 3169 AstFinder.getFieldInClass(unit1, "B", "b2"), intType, intType);
3152 } 3170 }
3153 3171
3154 // Test inference between static and instance fields 3172 // Test inference between static and instance fields
3155 void test_perform_inference_instance() { 3173 void test_perform_inference_instance() {
3156 List<Source> sources = newSources({ 3174 List<Source> sources = newSources({
3157 '/a.dart': ''' 3175 '/a.dart': '''
3158 import 'b.dart'; 3176 import 'b.dart';
3159 class A { 3177 class A {
3160 final a2 = new B().b2; 3178 final a2 = new B().b2;
3161 } 3179 }
(...skipping 13 matching lines...) Expand all
3175 }); 3193 });
3176 InterfaceType intType = context.typeProvider.intType; 3194 InterfaceType intType = context.typeProvider.intType;
3177 DartType dynamicType = context.typeProvider.dynamicType; 3195 DartType dynamicType = context.typeProvider.dynamicType;
3178 3196
3179 computeResult( 3197 computeResult(
3180 new LibrarySpecificUnit(sources[0], sources[0]), RESOLVED_UNIT7); 3198 new LibrarySpecificUnit(sources[0], sources[0]), RESOLVED_UNIT7);
3181 CompilationUnit unit0 = outputs[RESOLVED_UNIT7]; 3199 CompilationUnit unit0 = outputs[RESOLVED_UNIT7];
3182 3200
3183 // A.a2 should now be resolved on the rhs, but not yet inferred. 3201 // A.a2 should now be resolved on the rhs, but not yet inferred.
3184 assertVariableDeclarationTypes( 3202 assertVariableDeclarationTypes(
3185 getFieldInClass(unit0, "A", "a2"), dynamicType, dynamicType); 3203 AstFinder.getFieldInClass(unit0, "A", "a2"), dynamicType, dynamicType);
3186 3204
3187 // B.b2 shoud be resolved on the rhs, but not yet inferred. 3205 // B.b2 shoud be resolved on the rhs, but not yet inferred.
3188 assertVariableDeclarationTypes( 3206 assertVariableDeclarationTypes(
3189 getFieldInClass(unit0, "B", "b2"), dynamicType, intType); 3207 AstFinder.getFieldInClass(unit0, "B", "b2"), dynamicType, intType);
3190 3208
3191 computeResult( 3209 computeResult(
3192 new LibrarySpecificUnit(sources[1], sources[1]), RESOLVED_UNIT7); 3210 new LibrarySpecificUnit(sources[1], sources[1]), RESOLVED_UNIT7);
3193 3211
3194 // A.a2 should now be fully resolved and inferred. 3212 // A.a2 should now be fully resolved and inferred.
3195 assertVariableDeclarationTypes( 3213 assertVariableDeclarationTypes(
3196 getFieldInClass(unit0, "A", "a2"), dynamicType, dynamicType); 3214 AstFinder.getFieldInClass(unit0, "A", "a2"), dynamicType, dynamicType);
3197 3215
3198 // B.b2 should now be fully resolved and inferred. 3216 // B.b2 should now be fully resolved and inferred.
3199 assertVariableDeclarationTypes( 3217 assertVariableDeclarationTypes(
3200 getFieldInClass(unit0, "B", "b2"), intType, intType); 3218 AstFinder.getFieldInClass(unit0, "B", "b2"), intType, intType);
3201 } 3219 }
3202 } 3220 }
3203 3221
3204 @reflectiveTest 3222 @reflectiveTest
3205 class ResolveLibraryTypeNamesTaskTest extends _AbstractDartTaskTest { 3223 class ResolveLibraryTypeNamesTaskTest extends _AbstractDartTaskTest {
3206 test_perform() { 3224 test_perform() {
3207 Source sourceLib = newSource( 3225 Source sourceLib = newSource(
3208 '/my_lib.dart', 3226 '/my_lib.dart',
3209 ''' 3227 '''
3210 library my_lib; 3228 library my_lib;
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
3530 AnalysisTarget source = newSource( 3548 AnalysisTarget source = newSource(
3531 '/test.dart', 3549 '/test.dart',
3532 ''' 3550 '''
3533 var piFirst = true; 3551 var piFirst = true;
3534 var pi = piFirst ? 3.14 : tau / 2; 3552 var pi = piFirst ? 3.14 : tau / 2;
3535 var tau = piFirst ? pi * 2 : 6.28; 3553 var tau = piFirst ? pi * 2 : 6.28;
3536 '''); 3554 ''');
3537 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT9); 3555 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT9);
3538 CompilationUnit unit = outputs[RESOLVED_UNIT9]; 3556 CompilationUnit unit = outputs[RESOLVED_UNIT9];
3539 VariableElement piFirst = 3557 VariableElement piFirst =
3540 getTopLevelVariable(unit, 'piFirst').name.staticElement; 3558 AstFinder.getTopLevelVariable(unit, 'piFirst').name.staticElement;
3541 VariableElement pi = getTopLevelVariable(unit, 'pi').name.staticElement; 3559 VariableElement pi =
3542 VariableElement tau = getTopLevelVariable(unit, 'tau').name.staticElement; 3560 AstFinder.getTopLevelVariable(unit, 'pi').name.staticElement;
3543 Expression piFirstUse = (getTopLevelVariable(unit, 'tau').initializer 3561 VariableElement tau =
3544 as ConditionalExpression).condition; 3562 AstFinder.getTopLevelVariable(unit, 'tau').name.staticElement;
3563 Expression piFirstUse = (AstFinder
3564 .getTopLevelVariable(unit, 'tau')
3565 .initializer as ConditionalExpression).condition;
3545 3566
3546 expect(piFirstUse.staticType, context.typeProvider.boolType); 3567 expect(piFirstUse.staticType, context.typeProvider.boolType);
3547 expect(piFirst.type, context.typeProvider.boolType); 3568 expect(piFirst.type, context.typeProvider.boolType);
3548 expect(pi.type.isDynamic, isTrue); 3569 expect(pi.type.isDynamic, isTrue);
3549 expect(tau.type.isDynamic, isTrue); 3570 expect(tau.type.isDynamic, isTrue);
3550 } 3571 }
3551 3572
3552 void test_perform_inference_cross_unit_cyclic() { 3573 void test_perform_inference_cross_unit_cyclic() {
3553 AnalysisTarget firstSource = newSource( 3574 AnalysisTarget firstSource = newSource(
3554 '/a.dart', 3575 '/a.dart',
(...skipping 20 matching lines...) Expand all
3575 computeResult( 3596 computeResult(
3576 new LibrarySpecificUnit(firstSource, firstSource), RESOLVED_UNIT9); 3597 new LibrarySpecificUnit(firstSource, firstSource), RESOLVED_UNIT9);
3577 CompilationUnit unit1 = outputs[RESOLVED_UNIT9]; 3598 CompilationUnit unit1 = outputs[RESOLVED_UNIT9];
3578 computeResult( 3599 computeResult(
3579 new LibrarySpecificUnit(secondSource, secondSource), RESOLVED_UNIT9); 3600 new LibrarySpecificUnit(secondSource, secondSource), RESOLVED_UNIT9);
3580 CompilationUnit unit2 = outputs[RESOLVED_UNIT9]; 3601 CompilationUnit unit2 = outputs[RESOLVED_UNIT9];
3581 3602
3582 InterfaceType intType = context.typeProvider.intType; 3603 InterfaceType intType = context.typeProvider.intType;
3583 3604
3584 assertVariableDeclarationTypes( 3605 assertVariableDeclarationTypes(
3585 getTopLevelVariable(unit1, "x"), intType, intType); 3606 AstFinder.getTopLevelVariable(unit1, "x"), intType, intType);
3586 assertVariableDeclarationTypes( 3607 assertVariableDeclarationTypes(
3587 getFieldInClass(unit1, "A", "x"), intType, intType); 3608 AstFinder.getFieldInClass(unit1, "A", "x"), intType, intType);
3588 3609
3589 assertVariableDeclarationTypes( 3610 assertVariableDeclarationTypes(
3590 getTopLevelVariable(unit2, "y"), intType, intType); 3611 AstFinder.getTopLevelVariable(unit2, "y"), intType, intType);
3591 assertVariableDeclarationTypes( 3612 assertVariableDeclarationTypes(
3592 getFieldInClass(unit2, "B", "y"), intType, intType); 3613 AstFinder.getFieldInClass(unit2, "B", "y"), intType, intType);
3593 3614
3594 List<Statement> statements = 3615 List<Statement> statements =
3595 getStatementsInTopLevelFunction(unit2, "test1"); 3616 AstFinder.getStatementsInTopLevelFunction(unit2, "test1");
3596 3617
3597 assertAssignmentStatementTypes(statements[1], intType, intType); 3618 assertAssignmentStatementTypes(statements[1], intType, intType);
3598 assertAssignmentStatementTypes(statements[2], intType, intType); 3619 assertAssignmentStatementTypes(statements[2], intType, intType);
3599 assertAssignmentStatementTypes(statements[3], intType, intType); 3620 assertAssignmentStatementTypes(statements[3], intType, intType);
3600 assertAssignmentStatementTypes(statements[4], intType, intType); 3621 assertAssignmentStatementTypes(statements[4], intType, intType);
3601 } 3622 }
3602 3623
3603 // Test that local variables in method bodies are inferred appropriately 3624 // Test that local variables in method bodies are inferred appropriately
3604 void test_perform_inference_cross_unit_instance() { 3625 void test_perform_inference_cross_unit_instance() {
3605 List<Source> sources = newSources({ 3626 List<Source> sources = newSources({
(...skipping 19 matching lines...) Expand all
3625 }); 3646 });
3626 List<dynamic> units = 3647 List<dynamic> units =
3627 computeLibraryResults(sources, RESOLVED_UNIT9).toList(); 3648 computeLibraryResults(sources, RESOLVED_UNIT9).toList();
3628 CompilationUnit unit0 = units[0]; 3649 CompilationUnit unit0 = units[0];
3629 CompilationUnit unit1 = units[1]; 3650 CompilationUnit unit1 = units[1];
3630 CompilationUnit unit2 = units[2]; 3651 CompilationUnit unit2 = units[2];
3631 3652
3632 InterfaceType intType = context.typeProvider.intType; 3653 InterfaceType intType = context.typeProvider.intType;
3633 3654
3634 assertVariableDeclarationTypes( 3655 assertVariableDeclarationTypes(
3635 getFieldInClass(unit0, "A", "a2"), intType, intType); 3656 AstFinder.getFieldInClass(unit0, "A", "a2"), intType, intType);
3636 3657
3637 assertVariableDeclarationTypes( 3658 assertVariableDeclarationTypes(
3638 getFieldInClass(unit1, "B", "b2"), intType, intType); 3659 AstFinder.getFieldInClass(unit1, "B", "b2"), intType, intType);
3639 3660
3640 List<Statement> statements = 3661 List<Statement> statements =
3641 getStatementsInTopLevelFunction(unit2, "test1"); 3662 AstFinder.getStatementsInTopLevelFunction(unit2, "test1");
3642 3663
3643 assertAssignmentStatementTypes(statements[1], intType, intType); 3664 assertAssignmentStatementTypes(statements[1], intType, intType);
3644 } 3665 }
3645 3666
3646 // Test inference interactions between local variables and fields 3667 // Test inference interactions between local variables and fields
3647 void test_perform_inference_cross_unit_instance_member() { 3668 void test_perform_inference_cross_unit_instance_member() {
3648 List<Source> sources = newSources({ 3669 List<Source> sources = newSources({
3649 '/a.dart': ''' 3670 '/a.dart': '''
3650 import 'b.dart'; 3671 import 'b.dart';
3651 var bar = new B(); 3672 var bar = new B();
(...skipping 20 matching lines...) Expand all
3672 }); 3693 });
3673 List<dynamic> units = 3694 List<dynamic> units =
3674 computeLibraryResults(sources, RESOLVED_UNIT9).toList(); 3695 computeLibraryResults(sources, RESOLVED_UNIT9).toList();
3675 CompilationUnit unit0 = units[0]; 3696 CompilationUnit unit0 = units[0];
3676 CompilationUnit unit2 = units[2]; 3697 CompilationUnit unit2 = units[2];
3677 3698
3678 InterfaceType intType = context.typeProvider.intType; 3699 InterfaceType intType = context.typeProvider.intType;
3679 InterfaceType stringType = context.typeProvider.stringType; 3700 InterfaceType stringType = context.typeProvider.stringType;
3680 3701
3681 assertVariableDeclarationStatementTypes( 3702 assertVariableDeclarationStatementTypes(
3682 getStatementsInTopLevelFunction(unit0, "foo")[0], stringType, intType); 3703 AstFinder.getStatementsInTopLevelFunction(unit0, "foo")[0],
3704 stringType,
3705 intType);
3683 assertVariableDeclarationStatementTypes( 3706 assertVariableDeclarationStatementTypes(
3684 getStatementsInTopLevelFunction(unit2, "foo")[0], stringType, intType); 3707 AstFinder.getStatementsInTopLevelFunction(unit2, "foo")[0],
3708 stringType,
3709 intType);
3685 } 3710 }
3686 3711
3687 // Test inference interactions between local variables and top level 3712 // Test inference interactions between local variables and top level
3688 // variables 3713 // variables
3689 void test_perform_inference_cross_unit_non_cyclic() { 3714 void test_perform_inference_cross_unit_non_cyclic() {
3690 AnalysisTarget firstSource = newSource( 3715 AnalysisTarget firstSource = newSource(
3691 '/a.dart', 3716 '/a.dart',
3692 ''' 3717 '''
3693 var x = 2; 3718 var x = 2;
3694 class A { static var x = 2; } 3719 class A { static var x = 2; }
(...skipping 16 matching lines...) Expand all
3711 new LibrarySpecificUnit(firstSource, firstSource), RESOLVED_UNIT9); 3736 new LibrarySpecificUnit(firstSource, firstSource), RESOLVED_UNIT9);
3712 CompilationUnit unit1 = outputs[RESOLVED_UNIT9]; 3737 CompilationUnit unit1 = outputs[RESOLVED_UNIT9];
3713 computeResult( 3738 computeResult(
3714 new LibrarySpecificUnit(secondSource, secondSource), RESOLVED_UNIT9); 3739 new LibrarySpecificUnit(secondSource, secondSource), RESOLVED_UNIT9);
3715 CompilationUnit unit2 = outputs[RESOLVED_UNIT9]; 3740 CompilationUnit unit2 = outputs[RESOLVED_UNIT9];
3716 3741
3717 InterfaceType intType = context.typeProvider.intType; 3742 InterfaceType intType = context.typeProvider.intType;
3718 InterfaceType stringType = context.typeProvider.stringType; 3743 InterfaceType stringType = context.typeProvider.stringType;
3719 3744
3720 assertVariableDeclarationTypes( 3745 assertVariableDeclarationTypes(
3721 getTopLevelVariable(unit1, "x"), intType, intType); 3746 AstFinder.getTopLevelVariable(unit1, "x"), intType, intType);
3722 assertVariableDeclarationTypes( 3747 assertVariableDeclarationTypes(
3723 getFieldInClass(unit1, "A", "x"), intType, intType); 3748 AstFinder.getFieldInClass(unit1, "A", "x"), intType, intType);
3724 3749
3725 assertVariableDeclarationTypes( 3750 assertVariableDeclarationTypes(
3726 getTopLevelVariable(unit2, "y"), intType, intType); 3751 AstFinder.getTopLevelVariable(unit2, "y"), intType, intType);
3727 assertVariableDeclarationTypes( 3752 assertVariableDeclarationTypes(
3728 getFieldInClass(unit2, "B", "y"), intType, intType); 3753 AstFinder.getFieldInClass(unit2, "B", "y"), intType, intType);
3729 3754
3730 List<Statement> statements = 3755 List<Statement> statements =
3731 getStatementsInTopLevelFunction(unit2, "test1"); 3756 AstFinder.getStatementsInTopLevelFunction(unit2, "test1");
3732 3757
3733 assertAssignmentStatementTypes(statements[0], intType, stringType); 3758 assertAssignmentStatementTypes(statements[0], intType, stringType);
3734 assertAssignmentStatementTypes(statements[1], intType, stringType); 3759 assertAssignmentStatementTypes(statements[1], intType, stringType);
3735 } 3760 }
3736 3761
3737 // Test that inference does not propagate from null 3762 // Test that inference does not propagate from null
3738 void test_perform_inference_cross_unit_static_instance() { 3763 void test_perform_inference_cross_unit_static_instance() {
3739 List<Source> sources = newSources({ 3764 List<Source> sources = newSources({
3740 '/a.dart': ''' 3765 '/a.dart': '''
3741 import 'b.dart'; 3766 import 'b.dart';
(...skipping 21 matching lines...) Expand all
3763 }); 3788 });
3764 List<dynamic> units = 3789 List<dynamic> units =
3765 computeLibraryResults(sources, RESOLVED_UNIT9).toList(); 3790 computeLibraryResults(sources, RESOLVED_UNIT9).toList();
3766 CompilationUnit unit0 = units[0]; 3791 CompilationUnit unit0 = units[0];
3767 CompilationUnit unit1 = units[1]; 3792 CompilationUnit unit1 = units[1];
3768 CompilationUnit unit2 = units[2]; 3793 CompilationUnit unit2 = units[2];
3769 3794
3770 InterfaceType intType = context.typeProvider.intType; 3795 InterfaceType intType = context.typeProvider.intType;
3771 3796
3772 assertVariableDeclarationTypes( 3797 assertVariableDeclarationTypes(
3773 getFieldInClass(unit0, "A", "a1"), intType, intType); 3798 AstFinder.getFieldInClass(unit0, "A", "a1"), intType, intType);
3774 assertVariableDeclarationTypes( 3799 assertVariableDeclarationTypes(
3775 getFieldInClass(unit0, "A", "a2"), intType, intType); 3800 AstFinder.getFieldInClass(unit0, "A", "a2"), intType, intType);
3776 3801
3777 assertVariableDeclarationTypes( 3802 assertVariableDeclarationTypes(
3778 getFieldInClass(unit1, "B", "b1"), intType, intType); 3803 AstFinder.getFieldInClass(unit1, "B", "b1"), intType, intType);
3779 assertVariableDeclarationTypes( 3804 assertVariableDeclarationTypes(
3780 getFieldInClass(unit1, "B", "b2"), intType, intType); 3805 AstFinder.getFieldInClass(unit1, "B", "b2"), intType, intType);
3781 3806
3782 List<Statement> statements = 3807 List<Statement> statements =
3783 getStatementsInTopLevelFunction(unit2, "test1"); 3808 AstFinder.getStatementsInTopLevelFunction(unit2, "test1");
3784 3809
3785 assertAssignmentStatementTypes(statements[1], intType, intType); 3810 assertAssignmentStatementTypes(statements[1], intType, intType);
3786 assertAssignmentStatementTypes(statements[2], intType, intType); 3811 assertAssignmentStatementTypes(statements[2], intType, intType);
3787 } 3812 }
3788 3813
3789 // Test inference across units (non-cyclic) 3814 // Test inference across units (non-cyclic)
3790 void test_perform_inference_local_variables() { 3815 void test_perform_inference_local_variables() {
3791 AnalysisTarget source = newSource( 3816 AnalysisTarget source = newSource(
3792 '/test.dart', 3817 '/test.dart',
3793 ''' 3818 '''
3794 test() { 3819 test() {
3795 int x = 3; 3820 int x = 3;
3796 x = "hi"; 3821 x = "hi";
3797 var y = 3; 3822 var y = 3;
3798 y = "hi"; 3823 y = "hi";
3799 } 3824 }
3800 '''); 3825 ''');
3801 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT9); 3826 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT9);
3802 CompilationUnit unit = outputs[RESOLVED_UNIT9]; 3827 CompilationUnit unit = outputs[RESOLVED_UNIT9];
3803 3828
3804 InterfaceType intType = context.typeProvider.intType; 3829 InterfaceType intType = context.typeProvider.intType;
3805 InterfaceType stringType = context.typeProvider.stringType; 3830 InterfaceType stringType = context.typeProvider.stringType;
3806 3831
3807 List<Statement> statements = getStatementsInTopLevelFunction(unit, "test"); 3832 List<Statement> statements =
3833 AstFinder.getStatementsInTopLevelFunction(unit, "test");
3808 3834
3809 assertVariableDeclarationStatementTypes(statements[0], intType, intType); 3835 assertVariableDeclarationStatementTypes(statements[0], intType, intType);
3810 assertAssignmentStatementTypes(statements[1], intType, stringType); 3836 assertAssignmentStatementTypes(statements[1], intType, stringType);
3811 assertVariableDeclarationStatementTypes(statements[2], intType, intType); 3837 assertVariableDeclarationStatementTypes(statements[2], intType, intType);
3812 assertAssignmentStatementTypes(statements[3], intType, stringType); 3838 assertAssignmentStatementTypes(statements[3], intType, stringType);
3813 } 3839 }
3814 3840
3815 // Test inference across units (cyclic) 3841 // Test inference across units (cyclic)
3816 void test_perform_inference_local_variables_fields() { 3842 void test_perform_inference_local_variables_fields() {
3817 AnalysisTarget source = newSource( 3843 AnalysisTarget source = newSource(
(...skipping 17 matching lines...) Expand all
3835 int y; // field def after use 3861 int y; // field def after use
3836 final z = 42; // should infer `int` 3862 final z = 42; // should infer `int`
3837 } 3863 }
3838 '''); 3864 ''');
3839 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT9); 3865 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT9);
3840 CompilationUnit unit = outputs[RESOLVED_UNIT9]; 3866 CompilationUnit unit = outputs[RESOLVED_UNIT9];
3841 3867
3842 InterfaceType intType = context.typeProvider.intType; 3868 InterfaceType intType = context.typeProvider.intType;
3843 InterfaceType stringType = context.typeProvider.stringType; 3869 InterfaceType stringType = context.typeProvider.stringType;
3844 3870
3845 List<Statement> statements = getStatementsInMethod(unit, "A", "test1"); 3871 List<Statement> statements =
3872 AstFinder.getStatementsInMethod(unit, "A", "test1");
3846 3873
3847 assertVariableDeclarationStatementTypes(statements[0], intType, intType); 3874 assertVariableDeclarationStatementTypes(statements[0], intType, intType);
3848 assertAssignmentStatementTypes(statements[1], intType, stringType); 3875 assertAssignmentStatementTypes(statements[1], intType, stringType);
3849 assertAssignmentStatementTypes(statements[2], intType, intType); 3876 assertAssignmentStatementTypes(statements[2], intType, intType);
3850 3877
3851 assertVariableDeclarationStatementTypes(statements[3], intType, intType); 3878 assertVariableDeclarationStatementTypes(statements[3], intType, intType);
3852 assertAssignmentStatementTypes(statements[4], intType, stringType); 3879 assertAssignmentStatementTypes(statements[4], intType, stringType);
3853 assertAssignmentStatementTypes(statements[5], intType, intType); 3880 assertAssignmentStatementTypes(statements[5], intType, intType);
3854 3881
3855 assertVariableDeclarationStatementTypes(statements[6], intType, intType); 3882 assertVariableDeclarationStatementTypes(statements[6], intType, intType);
3856 assertAssignmentStatementTypes(statements[7], intType, stringType); 3883 assertAssignmentStatementTypes(statements[7], intType, stringType);
3857 assertAssignmentStatementTypes(statements[8], intType, intType); 3884 assertAssignmentStatementTypes(statements[8], intType, intType);
3858 3885
3859 assertVariableDeclarationTypes( 3886 assertVariableDeclarationTypes(
3860 getFieldInClass(unit, "A", "x"), intType, intType); 3887 AstFinder.getFieldInClass(unit, "A", "x"), intType, intType);
3861 assertVariableDeclarationTypes( 3888 assertVariableDeclarationTypes(
3862 getFieldInClass(unit, "A", "z"), intType, intType); 3889 AstFinder.getFieldInClass(unit, "A", "z"), intType, intType);
3863 } 3890 }
3864 3891
3865 // Test inference of instance fields across units 3892 // Test inference of instance fields across units
3866 void test_perform_inference_local_variables_topLevel() { 3893 void test_perform_inference_local_variables_topLevel() {
3867 AnalysisTarget source = newSource( 3894 AnalysisTarget source = newSource(
3868 '/test.dart', 3895 '/test.dart',
3869 ''' 3896 '''
3870 int x = 0; 3897 int x = 0;
3871 3898
3872 test1() { 3899 test1() {
(...skipping 10 matching lines...) Expand all
3883 3910
3884 int y = 0; // field def after use 3911 int y = 0; // field def after use
3885 final z = 42; // should infer `int` 3912 final z = 42; // should infer `int`
3886 '''); 3913 ''');
3887 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT9); 3914 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT9);
3888 CompilationUnit unit = outputs[RESOLVED_UNIT9]; 3915 CompilationUnit unit = outputs[RESOLVED_UNIT9];
3889 3916
3890 InterfaceType intType = context.typeProvider.intType; 3917 InterfaceType intType = context.typeProvider.intType;
3891 InterfaceType stringType = context.typeProvider.stringType; 3918 InterfaceType stringType = context.typeProvider.stringType;
3892 3919
3893 List<Statement> statements = getStatementsInTopLevelFunction(unit, "test1"); 3920 List<Statement> statements =
3921 AstFinder.getStatementsInTopLevelFunction(unit, "test1");
3894 3922
3895 assertVariableDeclarationStatementTypes(statements[0], intType, intType); 3923 assertVariableDeclarationStatementTypes(statements[0], intType, intType);
3896 assertAssignmentStatementTypes(statements[1], intType, stringType); 3924 assertAssignmentStatementTypes(statements[1], intType, stringType);
3897 assertAssignmentStatementTypes(statements[2], intType, intType); 3925 assertAssignmentStatementTypes(statements[2], intType, intType);
3898 3926
3899 assertVariableDeclarationStatementTypes(statements[3], intType, intType); 3927 assertVariableDeclarationStatementTypes(statements[3], intType, intType);
3900 assertAssignmentStatementTypes(statements[4], intType, stringType); 3928 assertAssignmentStatementTypes(statements[4], intType, stringType);
3901 assertAssignmentStatementTypes(statements[5], intType, intType); 3929 assertAssignmentStatementTypes(statements[5], intType, intType);
3902 3930
3903 assertVariableDeclarationStatementTypes(statements[6], intType, intType); 3931 assertVariableDeclarationStatementTypes(statements[6], intType, intType);
3904 assertAssignmentStatementTypes(statements[7], intType, stringType); 3932 assertAssignmentStatementTypes(statements[7], intType, stringType);
3905 assertAssignmentStatementTypes(statements[8], intType, intType); 3933 assertAssignmentStatementTypes(statements[8], intType, intType);
3906 3934
3907 assertVariableDeclarationTypes( 3935 assertVariableDeclarationTypes(
3908 getTopLevelVariable(unit, "x"), intType, intType); 3936 AstFinder.getTopLevelVariable(unit, "x"), intType, intType);
3909 assertVariableDeclarationTypes( 3937 assertVariableDeclarationTypes(
3910 getTopLevelVariable(unit, "y"), intType, intType); 3938 AstFinder.getTopLevelVariable(unit, "y"), intType, intType);
3911 assertVariableDeclarationTypes( 3939 assertVariableDeclarationTypes(
3912 getTopLevelVariable(unit, "z"), intType, intType); 3940 AstFinder.getTopLevelVariable(unit, "z"), intType, intType);
3913 } 3941 }
3914 3942
3915 // Test inference between static and instance fields 3943 // Test inference between static and instance fields
3916 void test_perform_inference_null() { 3944 void test_perform_inference_null() {
3917 AnalysisTarget source = newSource( 3945 AnalysisTarget source = newSource(
3918 '/test.dart', 3946 '/test.dart',
3919 ''' 3947 '''
3920 var x = null; 3948 var x = null;
3921 var y = 3; 3949 var y = 3;
3922 class A { 3950 class A {
(...skipping 15 matching lines...) Expand all
3938 '''); 3966 ''');
3939 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT9); 3967 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT9);
3940 CompilationUnit unit = outputs[RESOLVED_UNIT9]; 3968 CompilationUnit unit = outputs[RESOLVED_UNIT9];
3941 3969
3942 InterfaceType intType = context.typeProvider.intType; 3970 InterfaceType intType = context.typeProvider.intType;
3943 InterfaceType stringType = context.typeProvider.stringType; 3971 InterfaceType stringType = context.typeProvider.stringType;
3944 DartType bottomType = context.typeProvider.bottomType; 3972 DartType bottomType = context.typeProvider.bottomType;
3945 DartType dynamicType = context.typeProvider.dynamicType; 3973 DartType dynamicType = context.typeProvider.dynamicType;
3946 3974
3947 assertVariableDeclarationTypes( 3975 assertVariableDeclarationTypes(
3948 getTopLevelVariable(unit, "x"), dynamicType, bottomType); 3976 AstFinder.getTopLevelVariable(unit, "x"), dynamicType, bottomType);
3949 assertVariableDeclarationTypes( 3977 assertVariableDeclarationTypes(
3950 getTopLevelVariable(unit, "y"), intType, intType); 3978 AstFinder.getTopLevelVariable(unit, "y"), intType, intType);
3951 assertVariableDeclarationTypes( 3979 assertVariableDeclarationTypes(
3952 getFieldInClass(unit, "A", "x"), dynamicType, bottomType); 3980 AstFinder.getFieldInClass(unit, "A", "x"), dynamicType, bottomType);
3953 assertVariableDeclarationTypes( 3981 assertVariableDeclarationTypes(
3954 getFieldInClass(unit, "A", "y"), intType, intType); 3982 AstFinder.getFieldInClass(unit, "A", "y"), intType, intType);
3955 assertVariableDeclarationTypes( 3983 assertVariableDeclarationTypes(
3956 getFieldInClass(unit, "A", "x2"), dynamicType, bottomType); 3984 AstFinder.getFieldInClass(unit, "A", "x2"), dynamicType, bottomType);
3957 assertVariableDeclarationTypes( 3985 assertVariableDeclarationTypes(
3958 getFieldInClass(unit, "A", "y2"), intType, intType); 3986 AstFinder.getFieldInClass(unit, "A", "y2"), intType, intType);
3959 3987
3960 List<Statement> statements = getStatementsInTopLevelFunction(unit, "test"); 3988 List<Statement> statements =
3989 AstFinder.getStatementsInTopLevelFunction(unit, "test");
3961 3990
3962 assertAssignmentStatementTypes(statements[0], dynamicType, stringType); 3991 assertAssignmentStatementTypes(statements[0], dynamicType, stringType);
3963 assertAssignmentStatementTypes(statements[1], intType, stringType); 3992 assertAssignmentStatementTypes(statements[1], intType, stringType);
3964 assertAssignmentStatementTypes(statements[2], dynamicType, stringType); 3993 assertAssignmentStatementTypes(statements[2], dynamicType, stringType);
3965 assertAssignmentStatementTypes(statements[3], intType, stringType); 3994 assertAssignmentStatementTypes(statements[3], intType, stringType);
3966 assertAssignmentStatementTypes(statements[4], dynamicType, stringType); 3995 assertAssignmentStatementTypes(statements[4], dynamicType, stringType);
3967 assertAssignmentStatementTypes(statements[5], intType, stringType); 3996 assertAssignmentStatementTypes(statements[5], intType, stringType);
3968 } 3997 }
3969 3998
3970 // Test inference between fields and method bodies 3999 // Test inference between fields and method bodies
3971 void test_perform_local_explicit_disabled() { 4000 void test_perform_local_explicit_disabled() {
3972 AnalysisTarget source = newSource( 4001 AnalysisTarget source = newSource(
3973 '/test.dart', 4002 '/test.dart',
3974 ''' 4003 '''
3975 test() { 4004 test() {
3976 int x = 3; 4005 int x = 3;
3977 x = "hi"; 4006 x = "hi";
3978 } 4007 }
3979 '''); 4008 ''');
3980 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT9); 4009 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT9);
3981 CompilationUnit unit = outputs[RESOLVED_UNIT9]; 4010 CompilationUnit unit = outputs[RESOLVED_UNIT9];
3982 4011
3983 InterfaceType intType = context.typeProvider.intType; 4012 InterfaceType intType = context.typeProvider.intType;
3984 InterfaceType stringType = context.typeProvider.stringType; 4013 InterfaceType stringType = context.typeProvider.stringType;
3985 4014
3986 List<Statement> statements = getStatementsInTopLevelFunction(unit, "test"); 4015 List<Statement> statements =
4016 AstFinder.getStatementsInTopLevelFunction(unit, "test");
3987 VariableDeclaration decl = 4017 VariableDeclaration decl =
3988 (statements[0] as VariableDeclarationStatement).variables.variables[0]; 4018 (statements[0] as VariableDeclarationStatement).variables.variables[0];
3989 expect(decl.element.type, intType); 4019 expect(decl.element.type, intType);
3990 expect(decl.initializer.staticType, intType); 4020 expect(decl.initializer.staticType, intType);
3991 4021
3992 ExpressionStatement statement = statements[1]; 4022 ExpressionStatement statement = statements[1];
3993 AssignmentExpression assgn = statement.expression; 4023 AssignmentExpression assgn = statement.expression;
3994 expect(assgn.leftHandSide.staticType, intType); 4024 expect(assgn.leftHandSide.staticType, intType);
3995 expect(assgn.rightHandSide.staticType, stringType); 4025 expect(assgn.rightHandSide.staticType, stringType);
3996 } 4026 }
(...skipping 17 matching lines...) Expand all
4014 a[0]; 4044 a[0];
4015 } 4045 }
4016 '''); 4046 ''');
4017 computeResult(new LibrarySpecificUnit(source, source), STRONG_MODE_ERRORS); 4047 computeResult(new LibrarySpecificUnit(source, source), STRONG_MODE_ERRORS);
4018 CompilationUnit unit = outputs[RESOLVED_UNIT]; 4048 CompilationUnit unit = outputs[RESOLVED_UNIT];
4019 4049
4020 // validate 4050 // validate
4021 _fillErrorListener(STRONG_MODE_ERRORS); 4051 _fillErrorListener(STRONG_MODE_ERRORS);
4022 expect(errorListener.errors, isEmpty); 4052 expect(errorListener.errors, isEmpty);
4023 4053
4024 List<Statement> statements = getStatementsInTopLevelFunction(unit, "main"); 4054 List<Statement> statements =
4055 AstFinder.getStatementsInTopLevelFunction(unit, "main");
4025 ExpressionStatement statement = statements[1]; 4056 ExpressionStatement statement = statements[1];
4026 IndexExpression idx = statement.expression; 4057 IndexExpression idx = statement.expression;
4027 expect(DynamicInvoke.get(idx.target), isNotNull); 4058 expect(DynamicInvoke.get(idx.target), isNotNull);
4028 expect(DynamicInvoke.get(idx.target), isNotNull); 4059 expect(DynamicInvoke.get(idx.target), isNotNull);
4029 expect(DynamicInvoke.get(idx.target), isTrue); 4060 expect(DynamicInvoke.get(idx.target), isTrue);
4030 } 4061 }
4031 4062
4032 void test_perform_verifyError() { 4063 void test_perform_verifyError() {
4033 enableStrongMode(); 4064 enableStrongMode();
4034 AnalysisTarget source = newSource( 4065 AnalysisTarget source = newSource(
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
4207 4238
4208 /** 4239 /**
4209 * Enable strong mode in the current analysis context. 4240 * Enable strong mode in the current analysis context.
4210 */ 4241 */
4211 void enableStrongMode() { 4242 void enableStrongMode() {
4212 AnalysisOptionsImpl options = context.analysisOptions; 4243 AnalysisOptionsImpl options = context.analysisOptions;
4213 options.strongMode = true; 4244 options.strongMode = true;
4214 context.analysisOptions = options; 4245 context.analysisOptions = options;
4215 } 4246 }
4216 4247
4217 /**
4218 * Return the declaration of the class with the given [className] in the given
4219 * compilation [unit].
4220 */
4221 ClassDeclaration getClass(CompilationUnit unit, String className) {
4222 NodeList<CompilationUnitMember> unitMembers = unit.declarations;
4223 for (CompilationUnitMember unitMember in unitMembers) {
4224 if (unitMember is ClassDeclaration && unitMember.name.name == className) {
4225 return unitMember;
4226 }
4227 }
4228 fail('No class named $className in ${unit.element.source}');
4229 return null;
4230 }
4231
4232 /**
4233 * Return the declaration of the field with the given [fieldName] in the class
4234 * with the given [className] in the given compilation [unit].
4235 */
4236 VariableDeclaration getFieldInClass(
4237 CompilationUnit unit, String className, String fieldName) {
4238 ClassDeclaration unitMember = getClass(unit, className);
4239 NodeList<ClassMember> classMembers = unitMember.members;
4240 for (ClassMember classMember in classMembers) {
4241 if (classMember is FieldDeclaration) {
4242 NodeList<VariableDeclaration> fields = classMember.fields.variables;
4243 for (VariableDeclaration field in fields) {
4244 if (field.name.name == fieldName) {
4245 return field;
4246 }
4247 }
4248 }
4249 }
4250 fail('No field named $fieldName in $className');
4251 return null;
4252 }
4253
4254 /**
4255 * Return the declaration of the method with the given [methodName] in the
4256 * class with the given [className] in the given compilation [unit].
4257 */
4258 MethodDeclaration getMethodInClass(
4259 CompilationUnit unit, String className, String methodName) {
4260 ClassDeclaration unitMember = getClass(unit, className);
4261 NodeList<ClassMember> classMembers = unitMember.members;
4262 for (ClassMember classMember in classMembers) {
4263 if (classMember is MethodDeclaration) {
4264 if (classMember.name.name == methodName) {
4265 return classMember;
4266 }
4267 }
4268 }
4269 fail('No method named $methodName in $className');
4270 return null;
4271 }
4272
4273 List<Statement> getStatementsInMethod(
4274 CompilationUnit unit, String className, String methodName) {
4275 MethodDeclaration method = getMethodInClass(unit, className, methodName);
4276 BlockFunctionBody body = method.body;
4277 return body.block.statements;
4278 }
4279
4280 List<Statement> getStatementsInTopLevelFunction(
4281 CompilationUnit unit, String functionName) {
4282 FunctionDeclaration function = getTopLevelFunction(unit, functionName);
4283 BlockFunctionBody body = function.functionExpression.body;
4284 return body.block.statements;
4285 }
4286
4287 /**
4288 * Return the declaration of the top-level function with the given
4289 * [functionName] in the given compilation [unit].
4290 */
4291 FunctionDeclaration getTopLevelFunction(
4292 CompilationUnit unit, String functionName) {
4293 NodeList<CompilationUnitMember> unitMembers = unit.declarations;
4294 for (CompilationUnitMember unitMember in unitMembers) {
4295 if (unitMember is FunctionDeclaration) {
4296 if (unitMember.name.name == functionName) {
4297 return unitMember;
4298 }
4299 }
4300 }
4301 return null;
4302 }
4303
4304 /**
4305 * Return the declaration of the top-level variable with the given
4306 * [variableName] in the given compilation [unit].
4307 */
4308 VariableDeclaration getTopLevelVariable(
4309 CompilationUnit unit, String variableName) {
4310 NodeList<CompilationUnitMember> unitMembers = unit.declarations;
4311 for (CompilationUnitMember unitMember in unitMembers) {
4312 if (unitMember is TopLevelVariableDeclaration) {
4313 NodeList<VariableDeclaration> variables =
4314 unitMember.variables.variables;
4315 for (VariableDeclaration variable in variables) {
4316 if (variable.name.name == variableName) {
4317 return variable;
4318 }
4319 }
4320 }
4321 }
4322 return null;
4323 }
4324
4325 void setUp() { 4248 void setUp() {
4326 super.setUp(); 4249 super.setUp();
4327 emptySource = newSource('/test.dart'); 4250 emptySource = newSource('/test.dart');
4328 } 4251 }
4329 4252
4330 /** 4253 /**
4331 * Fill [errorListener] with [result] errors in the current [task]. 4254 * Fill [errorListener] with [result] errors in the current [task].
4332 */ 4255 */
4333 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { 4256 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) {
4334 List<AnalysisError> errors = task.outputs[result]; 4257 List<AnalysisError> errors = task.outputs[result];
4335 expect(errors, isNotNull, reason: result.name); 4258 expect(errors, isNotNull, reason: result.name);
4336 errorListener = new GatheringErrorListener(); 4259 errorListener = new GatheringErrorListener();
4337 errorListener.addAll(errors); 4260 errorListener.addAll(errors);
4338 } 4261 }
4339 } 4262 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698