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

Unified Diff: compiler/javatests/com/google/dart/compiler/parser/SyntaxTest.java

Issue 10555034: Fix parse error on dead code in a switch statement (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: # Created 8 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 side-by-side diff with in-line comments
Download patch
Index: compiler/javatests/com/google/dart/compiler/parser/SyntaxTest.java
diff --git a/compiler/javatests/com/google/dart/compiler/parser/SyntaxTest.java b/compiler/javatests/com/google/dart/compiler/parser/SyntaxTest.java
index 78510d7d6e23c8425d13c66e139320d6d280e145..467bd37f1b196c62ef3f517de9c360f9eadb29ec 100644
--- a/compiler/javatests/com/google/dart/compiler/parser/SyntaxTest.java
+++ b/compiler/javatests/com/google/dart/compiler/parser/SyntaxTest.java
@@ -53,7 +53,7 @@ public class SyntaxTest extends AbstractParserTest {
" void set g2=(int v) {}",
"}"));
}
-
+
public void test_const() {
DartUnit unit = parseUnit(getName() + ".dart", makeCode(
"// filler filler filler filler filler filler filler filler filler filler",
@@ -674,6 +674,45 @@ public class SyntaxTest extends AbstractParserTest {
ParserErrorCode.CONTINUE_OUTSIDE_OF_LOOP, 12, 42);
}
+ public void testRedundantAbruptlyTermainatedCaseStatement() throws Exception {
+ parseUnit("phony_reduntant_abruptly_terminated_case_statement.dart",
+ Joiner.on("\n").join(
+ "func () {",
+ " switch (0) {",
+ " case 0: ",
+ " return 0; ",
+ " break;", // warn dead code
+ " case 1: ",
+ " return 1; ",
+ " var foo = 1;", // warn dead code
+ " case 2:",
+ " return 2;",
+ " var bar = 2;", // warn dead code
+ " break;", // no warning here
+ " default:",
+ " return -1;",
+ " var baz = -1;", // warn dead code
+ " break;", // no warning here
+ " }",
+ "}"),
+ ParserErrorCode.UNREACHABLE_CODE_IN_CASE, 5, 6,
+ ParserErrorCode.UNREACHABLE_CODE_IN_CASE, 8, 6,
+ ParserErrorCode.UNREACHABLE_CODE_IN_CASE, 11, 6,
+ ParserErrorCode.UNREACHABLE_CODE_IN_CASE, 15, 6);
+ }
+
+ public void testCornerCaseLabelInSwitch() throws Exception {
+ // The parser used to just accept this statement.
+ parseUnit("phony_reduntant_abruptly_terminated_case_statement.dart",
+ Joiner.on("\n").join(
+ "func () {",
+ " switch (0) {",
+ " label1: ", // no case, default or statement follows.
+ " }",
+ "}"),
+ ParserErrorCode.LABEL_NOT_FOLLOWED_BY_CASE_OR_DEFAULT, 3, 9);
+ }
+
public void testBogusEscapedNewline() throws Exception {
parseUnit("phony_bogus_escaped_newline.dart",
Joiner.on("\n").join(

Powered by Google App Engine
This is Rietveld 408576698