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

Unified Diff: runtime/vm/parser.cc

Issue 51533003: Compile time error if name is used before variable is declared (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 2 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
Index: runtime/vm/parser.cc
===================================================================
--- runtime/vm/parser.cc (revision 29679)
+++ runtime/vm/parser.cc (working copy)
@@ -5260,10 +5260,27 @@
TRACE_PARSER("ParseVariableDeclaration");
ASSERT(IsIdentifier());
const intptr_t ident_pos = TokenPos();
- LocalVariable* variable =
- new LocalVariable(ident_pos, *CurrentLiteral(), type);
+ const String& ident = *CurrentLiteral();
+ LocalVariable* variable = new LocalVariable(ident_pos, ident, type);
ASSERT(current_block_ != NULL);
ASSERT(current_block_->scope != NULL);
+ const intptr_t previous_pos =
+ current_block_->scope->PreviousReferencePos(ident);
+ if (previous_pos >= 0) {
+ ASSERT(!script_.IsNull());
+ if (script_.HasSource()) {
+ intptr_t line_number;
+ script_.GetTokenLocation(previous_pos, &line_number, NULL);
Ivan Posva 2013/11/01 16:35:12 Since we are only getting the line number here we
hausner 2013/11/01 16:42:51 True. I figured line numbers make less sense if a
+ ErrorMsg(ident_pos,
+ "identifier '%s' previously used in line %" Pd "",
+ ident.ToCString(),
+ line_number);
+ } else {
+ ErrorMsg(ident_pos,
+ "identifier '%s' previously used in this scope",
+ ident.ToCString());
+ }
+ }
ConsumeToken(); // Variable identifier.
AstNode* initialization = NULL;
if (CurrentToken() == Token::kASSIGN) {
@@ -8776,6 +8793,9 @@
TRACE_PARSER("ResolveIdentInLocalScope");
// First try to find the identifier in the nested local scopes.
LocalVariable* local = LookupLocalScope(ident);
+ if (current_block_ != NULL) {
+ current_block_->scope->AddReferencedName(ident_pos, ident);
+ }
if (local != NULL) {
if (node != NULL) {
if (local->IsConst()) {
@@ -9120,6 +9140,11 @@
}
QualIdent type_name;
if (finalization == ClassFinalizer::kIgnore) {
+ if (!is_top_level_ && (current_block_ != NULL)) {
+ // Add the library prefix or type class name to the list of referenced
+ // names of this scope, even if the type is ignored.
+ current_block_->scope->AddReferencedName(TokenPos(), *CurrentLiteral());
+ }
SkipQualIdent();
} else {
ParseQualIdent(&type_name);
« no previous file with comments | « runtime/lib/typed_data.dart ('k') | runtime/vm/scopes.h » ('j') | runtime/vm/scopes.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698