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

Unified Diff: pkg/analyzer/test/generated/hint_code_test.dart

Issue 1943443002: If an if or do statement always exits, following statements are dead. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Add tests Created 4 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: pkg/analyzer/test/generated/hint_code_test.dart
diff --git a/pkg/analyzer/test/generated/hint_code_test.dart b/pkg/analyzer/test/generated/hint_code_test.dart
index bc5c9829dd2dfc060ebf4a60ee98ad0fe4af944d..585f24d4e725bc9d037427ec6c659c5c9c618ddb 100644
--- a/pkg/analyzer/test/generated/hint_code_test.dart
+++ b/pkg/analyzer/test/generated/hint_code_test.dart
@@ -619,6 +619,105 @@ f() {
verify([source]);
}
+ void test_deadCode_statementAfterExitingIf_function() {
Brian Wilkerson 2016/05/04 17:28:19 If ExitDetector worked, then most of these tests c
srawlins 2016/05/19 18:36:44 You're right. Dramatically reduced tests!
+ Source source = addSource(r'''
+f() {
+ if (1 > 2) {
+ return;
+ } else {
+ return;
+ }
+ var two = 2;
+}''');
+ computeLibrarySourceErrors(source);
+ assertErrors(source, [HintCode.DEAD_CODE]);
+ verify([source]);
+ }
+
+ void test_deadCode_statementAfterExitingIf_returns() {
+ Source source = addSource(r'''
+f() {
+ if (1 > 2) {
+ return;
+ } else {
+ return;
+ }
+ var one = 1;
+}''');
+ computeLibrarySourceErrors(source);
+ assertErrors(source, [HintCode.DEAD_CODE]);
+ verify([source]);
+ }
+
+ void test_deadCode_statementAfterExitingIf_throws() {
+ Source source = addSource(r'''
+f() {
+ if (1 > 2) {
+ throw 'Stopping in then';
+ } else {
+ throw 'Stopping in else';
+ }
+ var one = 1;
+}''');
+ computeLibrarySourceErrors(source);
+ assertErrors(source, [HintCode.DEAD_CODE]);
+ verify([source]);
+ }
+
+ void test_deadCode_statementAfterExitingIf_loops() {
+ Source source = addSource(r'''
+f() {
+ if (1 > 2) {
+ while (true) { print('Hello'); }
+ } else {
+ while (true) { print('Hello'); }
+ }
+ var one = 1;
+}''');
+ computeLibrarySourceErrors(source);
+ assertErrors(source, [HintCode.DEAD_CODE]);
+ verify([source]);
+ }
+
+ void test_deadCode_statementAfterExitingDo_returns() {
+ Source source = addSource(r'''
+f() {
+ do {
+ return;
+ } while (1 < 0);
+ var one = 1;
+}''');
+ computeLibrarySourceErrors(source);
+ assertErrors(source, [HintCode.DEAD_CODE]);
+ verify([source]);
+ }
+
+ void test_deadCode_statementAfterExitingDo_throws() {
+ Source source = addSource(r'''
+f() {
+ do {
+ throw 'me';
+ } while (1 < 0);
+ var one = 1;
+}''');
+ computeLibrarySourceErrors(source);
+ assertErrors(source, [HintCode.DEAD_CODE]);
+ verify([source]);
+ }
+
+ void test_deadCode_statementAfterExitingDo_loops() {
+ Source source = addSource(r'''
+f() {
+ do {
+ while (true) print('Hello');
+ } while (1 < 0);
+ var one = 1;
+}''');
+ computeLibrarySourceErrors(source);
+ assertErrors(source, [HintCode.DEAD_CODE]);
+ verify([source]);
+ }
+
void test_deprecatedAnnotationUse_assignment() {
Source source = addSource(r'''
class A {

Powered by Google App Engine
This is Rietveld 408576698