Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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.strong_mode_test; | 5 library analyzer.test.generated.strong_mode_test; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 50 AsserterBuilder<Asserter<DartType>, InterfaceType> _isListOf; | 50 AsserterBuilder<Asserter<DartType>, InterfaceType> _isListOf; |
| 51 AsserterBuilder2<Asserter<DartType>, Asserter<DartType>, InterfaceType> | 51 AsserterBuilder2<Asserter<DartType>, Asserter<DartType>, InterfaceType> |
| 52 _isMapOf; | 52 _isMapOf; |
| 53 AsserterBuilder<List<Asserter<DartType>>, InterfaceType> _isStreamOf; | 53 AsserterBuilder<List<Asserter<DartType>>, InterfaceType> _isStreamOf; |
| 54 AsserterBuilder<DartType, DartType> _isType; | 54 AsserterBuilder<DartType, DartType> _isType; |
| 55 | 55 |
| 56 AsserterBuilder<Element, DartType> _hasElement; | 56 AsserterBuilder<Element, DartType> _hasElement; |
| 57 AsserterBuilder<DartType, DartType> _hasElementOf; | 57 AsserterBuilder<DartType, DartType> _hasElementOf; |
| 58 | 58 |
| 59 @override | 59 @override |
| 60 void setUp() { | 60 Future<TestAnalysisResult> computeAnalysisResult(Source source) async { |
|
Brian Wilkerson
2017/01/23 20:50:34
I assume that none of the initializations that wer
scheglov
2017/01/23 21:26:33
They are not, but it is still wasteful.
I changed
| |
| 61 super.setUp(); | 61 TestAnalysisResult result = await super.computeAnalysisResult(source); |
| 62 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); | |
| 63 options.strongMode = true; | |
| 64 resetWith(options: options); | |
| 65 _assertions = new TypeAssertions(typeProvider); | 62 _assertions = new TypeAssertions(typeProvider); |
| 66 _isType = _assertions.isType; | 63 _isType = _assertions.isType; |
| 67 _hasElement = _assertions.hasElement; | 64 _hasElement = _assertions.hasElement; |
| 68 _isInstantiationOf = _assertions.isInstantiationOf; | 65 _isInstantiationOf = _assertions.isInstantiationOf; |
| 69 _isInt = _assertions.isInt; | 66 _isInt = _assertions.isInt; |
| 70 _isNum = _assertions.isNum; | 67 _isNum = _assertions.isNum; |
| 71 _isString = _assertions.isString; | 68 _isString = _assertions.isString; |
| 72 _isDynamic = _assertions.isDynamic; | 69 _isDynamic = _assertions.isDynamic; |
| 73 _isListOf = _assertions.isListOf; | 70 _isListOf = _assertions.isListOf; |
| 74 _isMapOf = _assertions.isMapOf; | 71 _isMapOf = _assertions.isMapOf; |
| 75 _isFunction2Of = _assertions.isFunction2Of; | 72 _isFunction2Of = _assertions.isFunction2Of; |
| 76 _hasElementOf = _assertions.hasElementOf; | 73 _hasElementOf = _assertions.hasElementOf; |
| 77 _isFutureOf = _isInstantiationOf(_hasElementOf(typeProvider.futureType)); | 74 _isFutureOf = _isInstantiationOf(_hasElementOf(typeProvider.futureType)); |
| 78 _isFutureOfDynamic = _isFutureOf([_isDynamic]); | 75 _isFutureOfDynamic = _isFutureOf([_isDynamic]); |
| 79 _isFutureOfInt = _isFutureOf([_isInt]); | 76 _isFutureOfInt = _isFutureOf([_isInt]); |
| 80 _isStreamOf = _isInstantiationOf(_hasElementOf(typeProvider.streamType)); | 77 _isStreamOf = _isInstantiationOf(_hasElementOf(typeProvider.streamType)); |
| 78 return result; | |
| 79 } | |
| 80 | |
| 81 @override | |
| 82 void setUp() { | |
| 83 super.setUp(); | |
| 84 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); | |
| 85 options.strongMode = true; | |
| 86 resetWith(options: options); | |
| 81 } | 87 } |
| 82 | 88 |
| 83 test_async_method_propagation() async { | 89 test_async_method_propagation() async { |
| 84 String code = r''' | 90 String code = r''' |
| 85 import "dart:async"; | 91 import "dart:async"; |
| 86 class A { | 92 class A { |
| 87 Future f0() => new Future.value(3); | 93 Future f0() => new Future.value(3); |
| 88 Future f1() async => new Future.value(3); | 94 Future f1() async => new Future.value(3); |
| 89 Future f2() async => await new Future.value(3); | 95 Future f2() async => await new Future.value(3); |
| 90 | 96 |
| (...skipping 2255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2346 } | 2352 } |
| 2347 | 2353 |
| 2348 test_foreachInference_dynamic_disabled() async { | 2354 test_foreachInference_dynamic_disabled() async { |
| 2349 String code = r''' | 2355 String code = r''' |
| 2350 main() { | 2356 main() { |
| 2351 var list = <int>[]; | 2357 var list = <int>[]; |
| 2352 for (dynamic v in list) { | 2358 for (dynamic v in list) { |
| 2353 v; // marker | 2359 v; // marker |
| 2354 } | 2360 } |
| 2355 }'''; | 2361 }'''; |
| 2356 await assertPropagatedIterationType(code, typeProvider.dynamicType, null); | 2362 CompilationUnit unit = await resolveSource(code); |
| 2357 await assertTypeOfMarkedExpression(code, typeProvider.dynamicType, null); | 2363 assertPropagatedIterationType(code, unit, typeProvider.dynamicType, null); |
| 2364 assertTypeOfMarkedExpression(code, unit, typeProvider.dynamicType, null); | |
| 2358 } | 2365 } |
| 2359 | 2366 |
| 2360 test_foreachInference_reusedVar_disabled() async { | 2367 test_foreachInference_reusedVar_disabled() async { |
| 2361 String code = r''' | 2368 String code = r''' |
| 2362 main() { | 2369 main() { |
| 2363 var list = <int>[]; | 2370 var list = <int>[]; |
| 2364 var v; | 2371 var v; |
| 2365 for (v in list) { | 2372 for (v in list) { |
| 2366 v; // marker | 2373 v; // marker |
| 2367 } | 2374 } |
| 2368 }'''; | 2375 }'''; |
| 2369 await assertPropagatedIterationType(code, typeProvider.dynamicType, null); | 2376 CompilationUnit unit = await resolveSource(code); |
| 2370 await assertTypeOfMarkedExpression(code, typeProvider.dynamicType, null); | 2377 assertPropagatedIterationType(code, unit, typeProvider.dynamicType, null); |
| 2378 assertTypeOfMarkedExpression(code, unit, typeProvider.dynamicType, null); | |
| 2371 } | 2379 } |
| 2372 | 2380 |
| 2373 test_foreachInference_var() async { | 2381 test_foreachInference_var() async { |
| 2374 String code = r''' | 2382 String code = r''' |
| 2375 main() { | 2383 main() { |
| 2376 var list = <int>[]; | 2384 var list = <int>[]; |
| 2377 for (var v in list) { | 2385 for (var v in list) { |
| 2378 v; // marker | 2386 v; // marker |
| 2379 } | 2387 } |
| 2380 }'''; | 2388 }'''; |
| 2381 await assertPropagatedIterationType(code, typeProvider.intType, null); | 2389 CompilationUnit unit = await resolveSource(code); |
| 2382 await assertTypeOfMarkedExpression(code, typeProvider.intType, null); | 2390 assertPropagatedIterationType(code, unit, typeProvider.intType, null); |
| 2391 assertTypeOfMarkedExpression(code, unit, typeProvider.intType, null); | |
| 2383 } | 2392 } |
| 2384 | 2393 |
| 2385 test_foreachInference_var_iterable() async { | 2394 test_foreachInference_var_iterable() async { |
| 2386 String code = r''' | 2395 String code = r''' |
| 2387 main() { | 2396 main() { |
| 2388 Iterable<int> list = <int>[]; | 2397 Iterable<int> list = <int>[]; |
| 2389 for (var v in list) { | 2398 for (var v in list) { |
| 2390 v; // marker | 2399 v; // marker |
| 2391 } | 2400 } |
| 2392 }'''; | 2401 }'''; |
| 2393 await assertPropagatedIterationType(code, typeProvider.intType, null); | 2402 CompilationUnit unit = await resolveSource(code); |
| 2394 await assertTypeOfMarkedExpression(code, typeProvider.intType, null); | 2403 assertPropagatedIterationType(code, unit, typeProvider.intType, null); |
| 2404 assertTypeOfMarkedExpression(code, unit, typeProvider.intType, null); | |
| 2395 } | 2405 } |
| 2396 | 2406 |
| 2397 test_foreachInference_var_stream() async { | 2407 test_foreachInference_var_stream() async { |
| 2398 String code = r''' | 2408 String code = r''' |
| 2399 import 'dart:async'; | 2409 import 'dart:async'; |
| 2400 main() async { | 2410 main() async { |
| 2401 Stream<int> stream = null; | 2411 Stream<int> stream = null; |
| 2402 await for (var v in stream) { | 2412 await for (var v in stream) { |
| 2403 v; // marker | 2413 v; // marker |
| 2404 } | 2414 } |
| 2405 }'''; | 2415 }'''; |
| 2406 await assertPropagatedIterationType(code, typeProvider.intType, null); | 2416 CompilationUnit unit = await resolveSource(code); |
| 2407 await assertTypeOfMarkedExpression(code, typeProvider.intType, null); | 2417 assertPropagatedIterationType(code, unit, typeProvider.intType, null); |
| 2418 assertTypeOfMarkedExpression(code, unit, typeProvider.intType, null); | |
| 2408 } | 2419 } |
| 2409 | 2420 |
| 2410 test_localVariableInference_bottom_disabled() async { | 2421 test_localVariableInference_bottom_disabled() async { |
| 2411 String code = r''' | 2422 String code = r''' |
| 2412 main() { | 2423 main() { |
| 2413 var v = null; | 2424 var v = null; |
| 2414 v; // marker | 2425 v; // marker |
| 2415 }'''; | 2426 }'''; |
| 2416 await assertPropagatedAssignedType(code, typeProvider.dynamicType, null); | 2427 CompilationUnit unit = await resolveSource(code); |
| 2417 await assertTypeOfMarkedExpression(code, typeProvider.dynamicType, null); | 2428 assertPropagatedAssignedType(code, unit, typeProvider.dynamicType, null); |
| 2429 assertTypeOfMarkedExpression(code, unit, typeProvider.dynamicType, null); | |
| 2418 } | 2430 } |
| 2419 | 2431 |
| 2420 test_localVariableInference_constant() async { | 2432 test_localVariableInference_constant() async { |
| 2421 String code = r''' | 2433 String code = r''' |
| 2422 main() { | 2434 main() { |
| 2423 var v = 3; | 2435 var v = 3; |
| 2424 v; // marker | 2436 v; // marker |
| 2425 }'''; | 2437 }'''; |
| 2426 await assertPropagatedAssignedType(code, typeProvider.intType, null); | 2438 CompilationUnit unit = await resolveSource(code); |
| 2427 await assertTypeOfMarkedExpression(code, typeProvider.intType, null); | 2439 assertPropagatedAssignedType(code, unit, typeProvider.intType, null); |
| 2440 assertTypeOfMarkedExpression(code, unit, typeProvider.intType, null); | |
| 2428 } | 2441 } |
| 2429 | 2442 |
| 2430 test_localVariableInference_declaredType_disabled() async { | 2443 test_localVariableInference_declaredType_disabled() async { |
| 2431 String code = r''' | 2444 String code = r''' |
| 2432 main() { | 2445 main() { |
| 2433 dynamic v = 3; | 2446 dynamic v = 3; |
| 2434 v; // marker | 2447 v; // marker |
| 2435 }'''; | 2448 }'''; |
| 2436 await assertPropagatedAssignedType(code, typeProvider.dynamicType, null); | 2449 CompilationUnit unit = await resolveSource(code); |
| 2437 await assertTypeOfMarkedExpression(code, typeProvider.dynamicType, null); | 2450 assertPropagatedAssignedType(code, unit, typeProvider.dynamicType, null); |
| 2451 assertTypeOfMarkedExpression(code, unit, typeProvider.dynamicType, null); | |
| 2438 } | 2452 } |
| 2439 | 2453 |
| 2440 test_localVariableInference_noInitializer_disabled() async { | 2454 test_localVariableInference_noInitializer_disabled() async { |
| 2441 String code = r''' | 2455 String code = r''' |
| 2442 main() { | 2456 main() { |
| 2443 var v; | 2457 var v; |
| 2444 v = 3; | 2458 v = 3; |
| 2445 v; // marker | 2459 v; // marker |
| 2446 }'''; | 2460 }'''; |
| 2447 await assertPropagatedAssignedType(code, typeProvider.dynamicType, null); | 2461 CompilationUnit unit = await resolveSource(code); |
| 2448 await assertTypeOfMarkedExpression(code, typeProvider.dynamicType, null); | 2462 assertPropagatedAssignedType(code, unit, typeProvider.dynamicType, null); |
| 2463 assertTypeOfMarkedExpression(code, unit, typeProvider.dynamicType, null); | |
| 2449 } | 2464 } |
| 2450 | 2465 |
| 2451 test_localVariableInference_transitive_field_inferred_lexical() async { | 2466 test_localVariableInference_transitive_field_inferred_lexical() async { |
| 2452 String code = r''' | 2467 String code = r''' |
| 2453 class A { | 2468 class A { |
| 2454 final x = 3; | 2469 final x = 3; |
| 2455 f() { | 2470 f() { |
| 2456 var v = x; | 2471 var v = x; |
| 2457 return v; // marker | 2472 return v; // marker |
| 2458 } | 2473 } |
| 2459 } | 2474 } |
| 2460 main() { | 2475 main() { |
| 2461 } | 2476 } |
| 2462 '''; | 2477 '''; |
| 2463 await assertPropagatedAssignedType(code, typeProvider.intType, null); | 2478 CompilationUnit unit = await resolveSource(code); |
| 2464 await assertTypeOfMarkedExpression(code, typeProvider.intType, null); | 2479 assertPropagatedAssignedType(code, unit, typeProvider.intType, null); |
| 2480 assertTypeOfMarkedExpression(code, unit, typeProvider.intType, null); | |
| 2465 } | 2481 } |
| 2466 | 2482 |
| 2467 test_localVariableInference_transitive_field_inferred_reversed() async { | 2483 test_localVariableInference_transitive_field_inferred_reversed() async { |
| 2468 String code = r''' | 2484 String code = r''' |
| 2469 class A { | 2485 class A { |
| 2470 f() { | 2486 f() { |
| 2471 var v = x; | 2487 var v = x; |
| 2472 return v; // marker | 2488 return v; // marker |
| 2473 } | 2489 } |
| 2474 final x = 3; | 2490 final x = 3; |
| 2475 } | 2491 } |
| 2476 main() { | 2492 main() { |
| 2477 } | 2493 } |
| 2478 '''; | 2494 '''; |
| 2479 await assertPropagatedAssignedType(code, typeProvider.intType, null); | 2495 CompilationUnit unit = await resolveSource(code); |
| 2480 await assertTypeOfMarkedExpression(code, typeProvider.intType, null); | 2496 assertPropagatedAssignedType(code, unit, typeProvider.intType, null); |
| 2497 assertTypeOfMarkedExpression(code, unit, typeProvider.intType, null); | |
| 2481 } | 2498 } |
| 2482 | 2499 |
| 2483 test_localVariableInference_transitive_field_lexical() async { | 2500 test_localVariableInference_transitive_field_lexical() async { |
| 2484 String code = r''' | 2501 String code = r''' |
| 2485 class A { | 2502 class A { |
| 2486 int x = 3; | 2503 int x = 3; |
| 2487 f() { | 2504 f() { |
| 2488 var v = x; | 2505 var v = x; |
| 2489 return v; // marker | 2506 return v; // marker |
| 2490 } | 2507 } |
| 2491 } | 2508 } |
| 2492 main() { | 2509 main() { |
| 2493 } | 2510 } |
| 2494 '''; | 2511 '''; |
| 2495 await assertPropagatedAssignedType(code, typeProvider.intType, null); | 2512 CompilationUnit unit = await resolveSource(code); |
| 2496 await assertTypeOfMarkedExpression(code, typeProvider.intType, null); | 2513 assertPropagatedAssignedType(code, unit, typeProvider.intType, null); |
| 2514 assertTypeOfMarkedExpression(code, unit, typeProvider.intType, null); | |
| 2497 } | 2515 } |
| 2498 | 2516 |
| 2499 test_localVariableInference_transitive_field_reversed() async { | 2517 test_localVariableInference_transitive_field_reversed() async { |
| 2500 String code = r''' | 2518 String code = r''' |
| 2501 class A { | 2519 class A { |
| 2502 f() { | 2520 f() { |
| 2503 var v = x; | 2521 var v = x; |
| 2504 return v; // marker | 2522 return v; // marker |
| 2505 } | 2523 } |
| 2506 int x = 3; | 2524 int x = 3; |
| 2507 } | 2525 } |
| 2508 main() { | 2526 main() { |
| 2509 } | 2527 } |
| 2510 '''; | 2528 '''; |
| 2511 await assertPropagatedAssignedType(code, typeProvider.intType, null); | 2529 CompilationUnit unit = await resolveSource(code); |
| 2512 await assertTypeOfMarkedExpression(code, typeProvider.intType, null); | 2530 assertPropagatedAssignedType(code, unit, typeProvider.intType, null); |
| 2531 assertTypeOfMarkedExpression(code, unit, typeProvider.intType, null); | |
| 2513 } | 2532 } |
| 2514 | 2533 |
| 2515 test_localVariableInference_transitive_list_local() async { | 2534 test_localVariableInference_transitive_list_local() async { |
| 2516 String code = r''' | 2535 String code = r''' |
| 2517 main() { | 2536 main() { |
| 2518 var x = <int>[3]; | 2537 var x = <int>[3]; |
| 2519 var v = x[0]; | 2538 var v = x[0]; |
| 2520 v; // marker | 2539 v; // marker |
| 2521 }'''; | 2540 }'''; |
| 2522 await assertPropagatedAssignedType(code, typeProvider.intType, null); | 2541 CompilationUnit unit = await resolveSource(code); |
| 2523 await assertTypeOfMarkedExpression(code, typeProvider.intType, null); | 2542 assertPropagatedAssignedType(code, unit, typeProvider.intType, null); |
| 2543 assertTypeOfMarkedExpression(code, unit, typeProvider.intType, null); | |
| 2524 } | 2544 } |
| 2525 | 2545 |
| 2526 test_localVariableInference_transitive_local() async { | 2546 test_localVariableInference_transitive_local() async { |
| 2527 String code = r''' | 2547 String code = r''' |
| 2528 main() { | 2548 main() { |
| 2529 var x = 3; | 2549 var x = 3; |
| 2530 var v = x; | 2550 var v = x; |
| 2531 v; // marker | 2551 v; // marker |
| 2532 }'''; | 2552 }'''; |
| 2533 await assertPropagatedAssignedType(code, typeProvider.intType, null); | 2553 CompilationUnit unit = await resolveSource(code); |
| 2534 await assertTypeOfMarkedExpression(code, typeProvider.intType, null); | 2554 assertPropagatedAssignedType(code, unit, typeProvider.intType, null); |
| 2555 assertTypeOfMarkedExpression(code, unit, typeProvider.intType, null); | |
| 2535 } | 2556 } |
| 2536 | 2557 |
| 2537 test_localVariableInference_transitive_toplevel_inferred_lexical() async { | 2558 test_localVariableInference_transitive_toplevel_inferred_lexical() async { |
| 2538 String code = r''' | 2559 String code = r''' |
| 2539 final x = 3; | 2560 final x = 3; |
| 2540 main() { | 2561 main() { |
| 2541 var v = x; | 2562 var v = x; |
| 2542 v; // marker | 2563 v; // marker |
| 2543 } | 2564 } |
| 2544 '''; | 2565 '''; |
| 2545 await assertPropagatedAssignedType(code, typeProvider.intType, null); | 2566 CompilationUnit unit = await resolveSource(code); |
| 2546 await assertTypeOfMarkedExpression(code, typeProvider.intType, null); | 2567 assertPropagatedAssignedType(code, unit, typeProvider.intType, null); |
| 2568 assertTypeOfMarkedExpression(code, unit, typeProvider.intType, null); | |
| 2547 } | 2569 } |
| 2548 | 2570 |
| 2549 test_localVariableInference_transitive_toplevel_inferred_reversed() async { | 2571 test_localVariableInference_transitive_toplevel_inferred_reversed() async { |
| 2550 String code = r''' | 2572 String code = r''' |
| 2551 main() { | 2573 main() { |
| 2552 var v = x; | 2574 var v = x; |
| 2553 v; // marker | 2575 v; // marker |
| 2554 } | 2576 } |
| 2555 final x = 3; | 2577 final x = 3; |
| 2556 '''; | 2578 '''; |
| 2557 await assertPropagatedAssignedType(code, typeProvider.intType, null); | 2579 CompilationUnit unit = await resolveSource(code); |
| 2558 await assertTypeOfMarkedExpression(code, typeProvider.intType, null); | 2580 assertPropagatedAssignedType(code, unit, typeProvider.intType, null); |
| 2581 assertTypeOfMarkedExpression(code, unit, typeProvider.intType, null); | |
| 2559 } | 2582 } |
| 2560 | 2583 |
| 2561 test_localVariableInference_transitive_toplevel_lexical() async { | 2584 test_localVariableInference_transitive_toplevel_lexical() async { |
| 2562 String code = r''' | 2585 String code = r''' |
| 2563 int x = 3; | 2586 int x = 3; |
| 2564 main() { | 2587 main() { |
| 2565 var v = x; | 2588 var v = x; |
| 2566 v; // marker | 2589 v; // marker |
| 2567 } | 2590 } |
| 2568 '''; | 2591 '''; |
| 2569 await assertPropagatedAssignedType(code, typeProvider.intType, null); | 2592 CompilationUnit unit = await resolveSource(code); |
| 2570 await assertTypeOfMarkedExpression(code, typeProvider.intType, null); | 2593 assertPropagatedAssignedType(code, unit, typeProvider.intType, null); |
| 2594 assertTypeOfMarkedExpression(code, unit, typeProvider.intType, null); | |
| 2571 } | 2595 } |
| 2572 | 2596 |
| 2573 test_localVariableInference_transitive_toplevel_reversed() async { | 2597 test_localVariableInference_transitive_toplevel_reversed() async { |
| 2574 String code = r''' | 2598 String code = r''' |
| 2575 main() { | 2599 main() { |
| 2576 var v = x; | 2600 var v = x; |
| 2577 v; // marker | 2601 v; // marker |
| 2578 } | 2602 } |
| 2579 int x = 3; | 2603 int x = 3; |
| 2580 '''; | 2604 '''; |
| 2581 await assertPropagatedAssignedType(code, typeProvider.intType, null); | 2605 CompilationUnit unit = await resolveSource(code); |
| 2582 await assertTypeOfMarkedExpression(code, typeProvider.intType, null); | 2606 assertPropagatedAssignedType(code, unit, typeProvider.intType, null); |
| 2607 assertTypeOfMarkedExpression(code, unit, typeProvider.intType, null); | |
| 2583 } | 2608 } |
| 2584 } | 2609 } |
| OLD | NEW |