| 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.hint_code_test; | 5 library analyzer.test.generated.hint_code_test; |
| 6 | 6 |
| 7 import 'package:analyzer/error/error.dart'; | 7 import 'package:analyzer/error/error.dart'; |
| 8 import 'package:analyzer/src/error/codes.dart'; | 8 import 'package:analyzer/src/error/codes.dart'; |
| 9 import 'package:analyzer/src/generated/engine.dart'; | 9 import 'package:analyzer/src/generated/engine.dart'; |
| 10 import 'package:analyzer/src/generated/parser.dart'; | 10 import 'package:analyzer/src/generated/parser.dart'; |
| (...skipping 2481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2492 | 2492 |
| 2493 class C { | 2493 class C { |
| 2494 F m() => ({@required String x}) => null; | 2494 F m() => ({@required String x}) => null; |
| 2495 } | 2495 } |
| 2496 '''); | 2496 '''); |
| 2497 await computeAnalysisResult(source); | 2497 await computeAnalysisResult(source); |
| 2498 assertErrors(source, [HintCode.MISSING_REQUIRED_PARAM]); | 2498 assertErrors(source, [HintCode.MISSING_REQUIRED_PARAM]); |
| 2499 verify([source]); | 2499 verify([source]); |
| 2500 } | 2500 } |
| 2501 | 2501 |
| 2502 test_strongMode_downCastCompositeNoHint() async { | 2502 test_strongMode_downCastCompositeHint() async { |
| 2503 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); | 2503 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); |
| 2504 options.strongMode = true; | 2504 options.strongMode = true; |
| 2505 options.strongModeHints = false; | 2505 options.strongModeHints = true; |
| 2506 resetWith(options: options); | 2506 resetWith(options: options); |
| 2507 Source source = addSource(r''' | 2507 Source source = addSource(r''' |
| 2508 main() { | 2508 main() { |
| 2509 List dynamicList = [ ]; | 2509 List dynamicList = [ ]; |
| 2510 List<int> list = dynamicList; | 2510 List<int> list = dynamicList; |
| 2511 print(list); | 2511 print(list); |
| 2512 }'''); | 2512 }'''); |
| 2513 await computeAnalysisResult(source); | 2513 await computeAnalysisResult(source); |
| 2514 assertNoErrors(source); | 2514 assertErrors(source, [StrongModeCode.DOWN_CAST_COMPOSITE]); |
| 2515 verify([source]); | 2515 verify([source]); |
| 2516 } | 2516 } |
| 2517 | 2517 |
| 2518 test_strongMode_downCastCompositeHint() async { | 2518 test_strongMode_downCastCompositeNoHint() async { |
| 2519 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); | 2519 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); |
| 2520 options.strongMode = true; | 2520 options.strongMode = true; |
| 2521 options.strongModeHints = true; | 2521 options.strongModeHints = false; |
| 2522 resetWith(options: options); | 2522 resetWith(options: options); |
| 2523 Source source = addSource(r''' | 2523 Source source = addSource(r''' |
| 2524 main() { | 2524 main() { |
| 2525 List dynamicList = [ ]; | 2525 List dynamicList = [ ]; |
| 2526 List<int> list = dynamicList; | 2526 List<int> list = dynamicList; |
| 2527 print(list); | 2527 print(list); |
| 2528 }'''); | 2528 }'''); |
| 2529 await computeAnalysisResult(source); | 2529 await computeAnalysisResult(source); |
| 2530 assertErrors(source, [StrongModeCode.DOWN_CAST_COMPOSITE]); | 2530 assertNoErrors(source); |
| 2531 verify([source]); | 2531 verify([source]); |
| 2532 } | 2532 } |
| 2533 | 2533 |
| 2534 test_strongMode_downCastCompositeWarn() async { | 2534 test_strongMode_downCastCompositeWarn() async { |
| 2535 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); | 2535 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); |
| 2536 applyToAnalysisOptions(options, { | 2536 applyToAnalysisOptions(options, { |
| 2537 AnalyzerOptions.analyzer: { | 2537 AnalyzerOptions.analyzer: { |
| 2538 AnalyzerOptions.errors: { | 2538 AnalyzerOptions.errors: { |
| 2539 StrongModeCode.DOWN_CAST_COMPOSITE.name: 'warning' | 2539 StrongModeCode.DOWN_CAST_COMPOSITE.name: 'warning' |
| 2540 }, | 2540 }, |
| 2541 } | 2541 } |
| 2542 }); | 2542 }); |
| 2543 options.strongMode = true; | 2543 options.strongMode = true; |
| 2544 options.strongModeHints = false; | 2544 options.strongModeHints = false; |
| 2545 resetWith(options: options); | 2545 resetWith(options: options); |
| 2546 Source source = addSource(r''' | 2546 Source source = addSource(r''' |
| 2547 main() { | 2547 main() { |
| 2548 List dynamicList = [ ]; | 2548 List dynamicList = [ ]; |
| 2549 List<int> list = dynamicList; | 2549 List<int> list = dynamicList; |
| 2550 print(list); | 2550 print(list); |
| 2551 }'''); | 2551 }'''); |
| 2552 await computeAnalysisResult(source); | 2552 await computeAnalysisResult(source); |
| 2553 assertErrors(source, [StrongModeCode.DOWN_CAST_COMPOSITE]); | 2553 assertErrors(source, [StrongModeCode.DOWN_CAST_COMPOSITE]); |
| 2554 verify([source]); | 2554 verify([source]); |
| 2555 } | 2555 } |
| 2556 | 2556 |
| 2557 test_strongMode_topLevelInstanceGetter() async { |
| 2558 resetWith(options: new AnalysisOptionsImpl()..strongMode = true); |
| 2559 Source source = addSource(r''' |
| 2560 class A { |
| 2561 int get g => 0; |
| 2562 } |
| 2563 var a = new A(); |
| 2564 var b = a.g; |
| 2565 '''); |
| 2566 await computeAnalysisResult(source); |
| 2567 assertErrors(source, [StrongModeCode.TOP_LEVEL_INSTANCE_GETTER]); |
| 2568 verify([source]); |
| 2569 } |
| 2570 |
| 2557 test_typeCheck_type_is_Null() async { | 2571 test_typeCheck_type_is_Null() async { |
| 2558 Source source = addSource(r''' | 2572 Source source = addSource(r''' |
| 2559 m(i) { | 2573 m(i) { |
| 2560 bool b = i is Null; | 2574 bool b = i is Null; |
| 2561 }'''); | 2575 }'''); |
| 2562 await computeAnalysisResult(source); | 2576 await computeAnalysisResult(source); |
| 2563 assertErrors(source, [HintCode.TYPE_CHECK_IS_NULL]); | 2577 assertErrors(source, [HintCode.TYPE_CHECK_IS_NULL]); |
| 2564 verify([source]); | 2578 verify([source]); |
| 2565 } | 2579 } |
| 2566 | 2580 |
| (...skipping 1641 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4208 n() { | 4222 n() { |
| 4209 var a = m(), b = m(); | 4223 var a = m(), b = m(); |
| 4210 } | 4224 } |
| 4211 }'''); | 4225 }'''); |
| 4212 await computeAnalysisResult(source); | 4226 await computeAnalysisResult(source); |
| 4213 assertErrors( | 4227 assertErrors( |
| 4214 source, [HintCode.USE_OF_VOID_RESULT, HintCode.USE_OF_VOID_RESULT]); | 4228 source, [HintCode.USE_OF_VOID_RESULT, HintCode.USE_OF_VOID_RESULT]); |
| 4215 verify([source]); | 4229 verify([source]); |
| 4216 } | 4230 } |
| 4217 } | 4231 } |
| OLD | NEW |