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

Unified Diff: compiler/java/com/google/dart/compiler/resolver/Resolver.java

Issue 11555015: Issue 2862. Report warning when 'default' of switch has fall-through. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years 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
« no previous file with comments | « no previous file | compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: compiler/java/com/google/dart/compiler/resolver/Resolver.java
diff --git a/compiler/java/com/google/dart/compiler/resolver/Resolver.java b/compiler/java/com/google/dart/compiler/resolver/Resolver.java
index 588a000633865213835e2aae137c03e0331aafb4..b0f3baedfa53074b13f8b52adfa2276bff3c4ddf 100644
--- a/compiler/java/com/google/dart/compiler/resolver/Resolver.java
+++ b/compiler/java/com/google/dart/compiler/resolver/Resolver.java
@@ -19,7 +19,6 @@ import com.google.dart.compiler.ast.DartBinaryExpression;
import com.google.dart.compiler.ast.DartBlock;
import com.google.dart.compiler.ast.DartBooleanLiteral;
import com.google.dart.compiler.ast.DartBreakStatement;
-import com.google.dart.compiler.ast.DartCase;
import com.google.dart.compiler.ast.DartCatchBlock;
import com.google.dart.compiler.ast.DartClass;
import com.google.dart.compiler.ast.DartComment;
@@ -1132,21 +1131,6 @@ public class Resolver {
return null;
}
- @Override
- public Element visitCase(DartCase node) {
- super.visitCase(node);
- List<DartStatement> statements = node.getStatements();
- // the last statement should be: break, continue, return, throw
- if (!statements.isEmpty()) {
- DartStatement lastStatement = statements.get(statements.size() - 1);
- if (!isValidLastSwitchCaseStatement(lastStatement)) {
- onError(lastStatement, ResolverErrorCode.SWITCH_CASE_FALL_THROUGH);
- }
- }
- // done
- return null;
- }
-
private boolean isValidLastSwitchCaseStatement(DartStatement statement) {
if (statement instanceof DartExprStmt) {
DartExprStmt exprStmt = (DartExprStmt) statement;
@@ -1160,9 +1144,23 @@ public class Resolver {
@Override
public Element visitSwitchMember(DartSwitchMember x) {
- getContext().pushScope("<switch member>");
- x.visitChildren(this);
- getContext().popScope();
+ // visit children
+ {
+ getContext().pushScope("<switch member>");
+ x.visitChildren(this);
+ getContext().popScope();
+ }
+ // check fall-through
+ {
+ List<DartStatement> statements = x.getStatements();
+ // the last statement should be: break, continue, return, throw
+ if (!statements.isEmpty()) {
+ DartStatement lastStatement = statements.get(statements.size() - 1);
+ if (!isValidLastSwitchCaseStatement(lastStatement)) {
+ onError(lastStatement, ResolverErrorCode.SWITCH_CASE_FALL_THROUGH);
+ }
+ }
+ }
return null;
}
« no previous file with comments | « no previous file | compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698