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

Unified Diff: runtime/vm/parser.cc

Issue 23640004: Require case expressions to be compile-time constants (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 4 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 | tests/co19/co19-runtime.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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();
« no previous file with comments | « no previous file | tests/co19/co19-runtime.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698