Index: runtime/vm/parser.cc |
=================================================================== |
--- runtime/vm/parser.cc (revision 26719) |
+++ runtime/vm/parser.cc (working copy) |
@@ -5903,7 +5903,7 @@ |
CaseNode* Parser::ParseCaseClause(LocalVariable* switch_expr_value, |
SourceLabel* case_label) { |
- TRACE_PARSER("ParseCaseStatement"); |
+ TRACE_PARSER("ParseCaseClause"); |
bool default_seen = false; |
const intptr_t case_pos = TokenPos(); |
// The case expressions node sequence does not own the enclosing scope. |
@@ -5915,7 +5915,7 @@ |
} |
ConsumeToken(); // Keyword case. |
const intptr_t expr_pos = TokenPos(); |
- AstNode* expr = ParseExpr(kAllowConst, kConsumeCascades); |
+ AstNode* expr = ParseExpr(kRequireConst, kConsumeCascades); |
AstNode* switch_expr_load = new LoadLocalNode(case_pos, |
switch_expr_value); |
AstNode* case_comparison = new ComparisonNode(expr_pos, |
@@ -5984,19 +5984,10 @@ |
SourceLabel* label = |
SourceLabel::New(switch_pos, label_name, SourceLabel::kSwitch); |
ConsumeToken(); |
- const bool parens_are_mandatory = false; |
- bool paren_found = false; |
- if (CurrentToken() == Token::kLPAREN) { |
- paren_found = true; |
- ConsumeToken(); |
- } else if (parens_are_mandatory) { |
- ErrorMsg("'(' expected"); |
- } |
+ ExpectToken(Token::kLPAREN); |
const intptr_t expr_pos = TokenPos(); |
AstNode* switch_expr = ParseExpr(kAllowConst, kConsumeCascades); |
- if (paren_found) { |
- ExpectToken(Token::kRPAREN); |
- } |
+ ExpectToken(Token::kRPAREN); |
ExpectToken(Token::kLBRACE); |
OpenBlock(); |
current_block_->scope->AddLabel(label); |
@@ -6033,7 +6024,7 @@ |
// the forward reference. |
case_label->ResolveForwardReference(); |
} else { |
- ErrorMsg(label_pos, "name '%s' already exists in scope", |
+ ErrorMsg(label_pos, "label '%s' already exists in scope", |
label_name->ToCString()); |
} |
ASSERT(case_label->kind() == SourceLabel::kCase); |
@@ -6055,6 +6046,9 @@ |
} |
} |
+ // TODO(hausner): Check that all expressions in case clauses are |
+ // of the same class, or implement int or String (issue 7307). |
+ |
// Check for unresolved label references. |
SourceLabel* unresolved_label = |
current_block_->scope->CheckUnresolvedLabels(); |