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

Unified Diff: runtime/vm/parser.cc

Issue 49253006: Compile time error on forward references to functions (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 1 month 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 | « runtime/bin/socket_patch.dart ('k') | tests/co19/co19-co19.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 29827)
+++ runtime/vm/parser.cc (working copy)
@@ -5410,19 +5410,6 @@
const intptr_t ident_pos = TokenPos();
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());
- intptr_t line_number;
- script_.GetTokenLocation(previous_pos, &line_number, NULL);
- ErrorMsg(ident_pos,
- "identifier '%s' previously used in line %" Pd "",
- ident.ToCString(),
- line_number);
- }
ConsumeToken(); // Variable identifier.
AstNode* initialization = NULL;
if (CurrentToken() == Token::kASSIGN) {
@@ -5443,6 +5430,27 @@
AstNode* null_expr = new LiteralNode(ident_pos, Instance::ZoneHandle());
initialization = new StoreLocalNode(ident_pos, variable, null_expr);
}
+
+ ASSERT(current_block_ != NULL);
+ const intptr_t previous_pos =
+ current_block_->scope->PreviousReferencePos(ident);
+ if (previous_pos >= 0) {
+ ASSERT(!script_.IsNull());
+ if (previous_pos > ident_pos) {
+ ErrorMsg(ident_pos,
+ "initializer of '%s' may not refer to itself",
+ ident.ToCString());
+
+ } else {
+ intptr_t line_number;
+ script_.GetTokenLocation(previous_pos, &line_number, NULL);
+ ErrorMsg(ident_pos,
+ "identifier '%s' previously used in line %" Pd "",
+ ident.ToCString(),
+ line_number);
+ }
+ }
+
// 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)) {
@@ -5557,8 +5565,24 @@
(LookaheadToken(1) != Token::kLPAREN)) {
result_type = ParseType(ClassFinalizer::kCanonicalize);
}
+ const intptr_t name_pos = TokenPos();
variable_name = ExpectIdentifier("function name expected");
function_name = variable_name;
+
+ // Check that the function name has not been referenced
+ // before this declaration.
+ ASSERT(current_block_ != NULL);
+ const intptr_t previous_pos =
+ current_block_->scope->PreviousReferencePos(*function_name);
+ if (previous_pos >= 0) {
+ ASSERT(!script_.IsNull());
+ intptr_t line_number;
+ script_.GetTokenLocation(previous_pos, &line_number, NULL);
+ ErrorMsg(name_pos,
+ "identifier '%s' previously used in line %" Pd "",
+ function_name->ToCString(),
+ line_number);
+ }
}
if (CurrentToken() != Token::kLPAREN) {
« no previous file with comments | « runtime/bin/socket_patch.dart ('k') | tests/co19/co19-co19.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698