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

Unified Diff: runtime/vm/parser.cc

Issue 22567003: Better error message for redefined local names (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 | no next file » | 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 25871)
+++ runtime/vm/parser.cc (working copy)
@@ -5140,8 +5140,17 @@
// Add variable to scope after parsing the initalizer expression.
// The expression must not be able to refer to the variable.
if (!current_block_->scope->AddVariable(variable)) {
- ErrorMsg(ident_pos, "identifier '%s' already defined",
- variable->name().ToCString());
+ LocalVariable* existing_var =
+ current_block_->scope->LookupVariable(variable->name(), true);
+ ASSERT(existing_var != NULL);
+ if (existing_var->owner() == current_block_->scope) {
+ ErrorMsg(ident_pos, "identifier '%s' already defined",
+ variable->name().ToCString());
+ } else {
+ ErrorMsg(ident_pos,
+ "'%s' from outer scope has already been used, cannot redefine",
+ variable->name().ToCString());
+ }
}
if (is_final || is_const) {
variable->set_is_final();
@@ -5300,8 +5309,18 @@
ASSERT(current_block_ != NULL);
ASSERT(current_block_->scope != NULL);
if (!current_block_->scope->AddVariable(function_variable)) {
- ErrorMsg(ident_pos, "identifier '%s' already defined",
- function_variable->name().ToCString());
+ LocalVariable* existing_var =
+ current_block_->scope->LookupVariable(function_variable->name(),
+ true);
+ ASSERT(existing_var != NULL);
+ if (existing_var->owner() == current_block_->scope) {
+ ErrorMsg(ident_pos, "identifier '%s' already defined",
+ function_variable->name().ToCString());
+ } else {
+ ErrorMsg(ident_pos,
+ "'%s' from outer scope has already been used, cannot redefine",
+ function_variable->name().ToCString());
+ }
}
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698