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

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

Issue 2064203002: Do not error on dead, mandated statements at end of switch cases (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Two tests Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 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/src/generated/engine.dart'; 7 import 'package:analyzer/src/generated/engine.dart';
8 import 'package:analyzer/src/generated/error.dart'; 8 import 'package:analyzer/src/generated/error.dart';
9 import 'package:analyzer/src/generated/source_io.dart'; 9 import 'package:analyzer/src/generated/source_io.dart';
10 import 'package:unittest/unittest.dart'; 10 import 'package:unittest/unittest.dart';
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 case 1: 466 case 1:
467 break; 467 break;
468 var a; 468 var a;
469 } 469 }
470 }'''); 470 }''');
471 computeLibrarySourceErrors(source); 471 computeLibrarySourceErrors(source);
472 assertErrors(source, [HintCode.DEAD_CODE]); 472 assertErrors(source, [HintCode.DEAD_CODE]);
473 verify([source]); 473 verify([source]);
474 } 474 }
475 475
476 void test_deadCode_deadFinalReturnInCase() {
477 Source source = addSource(r'''
478 f() {
479 switch (true) {
480 case true:
481 try {
482 int a = 1;
483 } finally {
484 return;
485 }
486 return;
487 default:
488 break;
489 }
490 }''');
491 computeLibrarySourceErrors(source);
492 assertErrors(source, [HintCode.DEAD_CODE]);
493 verify([source]);
494 }
495
496 void test_deadCode_deadFinalStatementInCase() {
497 Source source = addSource(r'''
498 f() {
499 switch (true) {
500 case true:
501 try {
502 int a = 1;
503 } finally {
504 return;
505 }
506 int b = 1;
507 default:
508 break;
509 }
510 }''');
511 computeLibrarySourceErrors(source);
512 // A single dead statement at the end of a switch case that is not a
513 // terminating statement will yield two errors.
514 assertErrors(source,
515 [HintCode.DEAD_CODE, StaticWarningCode.CASE_BLOCK_NOT_TERMINATED]);
516 verify([source]);
517 }
518
476 void test_deadCode_statementAfterBreak_inWhileStatement() { 519 void test_deadCode_statementAfterBreak_inWhileStatement() {
477 Source source = addSource(r''' 520 Source source = addSource(r'''
478 f(v) { 521 f(v) {
479 while(v) { 522 while(v) {
480 break; 523 break;
481 var a; 524 var a;
482 } 525 }
483 }'''); 526 }''');
484 computeLibrarySourceErrors(source); 527 computeLibrarySourceErrors(source);
485 assertErrors(source, [HintCode.DEAD_CODE]); 528 assertErrors(source, [HintCode.DEAD_CODE]);
(...skipping 3063 matching lines...) Expand 10 before | Expand all | Expand 10 after
3549 n() { 3592 n() {
3550 var a = m(), b = m(); 3593 var a = m(), b = m();
3551 } 3594 }
3552 }'''); 3595 }''');
3553 computeLibrarySourceErrors(source); 3596 computeLibrarySourceErrors(source);
3554 assertErrors( 3597 assertErrors(
3555 source, [HintCode.USE_OF_VOID_RESULT, HintCode.USE_OF_VOID_RESULT]); 3598 source, [HintCode.USE_OF_VOID_RESULT, HintCode.USE_OF_VOID_RESULT]);
3556 verify([source]); 3599 verify([source]);
3557 } 3600 }
3558 } 3601 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/resolver.dart ('k') | pkg/analyzer/test/generated/non_hint_code_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698