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

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

Issue 10716005: Fixes the scope of case labels so that duplicate case labels are properly detected (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
« no previous file with comments | « no previous file | compiler/java/com/google/dart/compiler/resolver/ResolverErrorCode.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 4fb19716de6e5d83c3ee294ba256fb28c845f920..697154ad9876ba88c29d0e6ce1d1de42fd0af671 100644
--- a/compiler/java/com/google/dart/compiler/resolver/Resolver.java
+++ b/compiler/java/com/google/dart/compiler/resolver/Resolver.java
@@ -913,6 +913,19 @@ public class Resolver {
}
}
+ private void addLabelToSwitchMember(DartSwitchMember x) {
+ DartLabel label = x.getLabel();
+ if (label != null) {
+ LabelElement currentLabel = label.getElement(); // TODO(zundel): Y U NO HAVE ELEMENT?
+ if (getContext().getScope().hasLocalLabel(label.getName())) {
+ onError(label, ResolverErrorCode.DUPLICATE_LABEL_IN_SWITCH_STATEMENT);
+ }
+ getContext().getScope().addLabel(currentLabel);
+ labelsInScopes.add(currentLabel);
+ }
+ }
+
+
@Override
public Element visitForStatement(DartForStatement x) {
getContext().pushScope("<for>");
@@ -937,6 +950,8 @@ public class Resolver {
getContext().pushScope("<switch member>");
x.visitChildren(this);
getContext().popScope();
+ // The scope of a label on the case statement is the case statement itself.
+ addLabelToSwitchMember(x);
return null;
}
« no previous file with comments | « no previous file | compiler/java/com/google/dart/compiler/resolver/ResolverErrorCode.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698