diff --git a/runtime/vm/parser.cc b/runtime/vm/parser.cc index e5d087b1ab1..741190f6735 100644 --- a/runtime/vm/parser.cc +++ b/runtime/vm/parser.cc @@ -6672,11 +6672,11 @@ AstNode* Parser::ParseVariableDeclaration(const AbstractType& type, const intptr_t ident_pos = TokenPos(); const String& ident = *CurrentLiteral(); ConsumeToken(); // Variable identifier. + const intptr_t assign_pos = TokenPos(); AstNode* initialization = NULL; LocalVariable* variable = NULL; if (CurrentToken() == Token::kASSIGN) { // Variable initialization. - const intptr_t assign_pos = TokenPos(); ConsumeToken(); AstNode* expr = ParseAwaitableExpr( is_const, kConsumeCascades, await_preamble); @@ -6695,7 +6695,7 @@ AstNode* Parser::ParseVariableDeclaration(const AbstractType& type, } else { // Initialize variable with null. variable = new(Z) LocalVariable( - ident_pos, ident, type); + assign_pos, ident, type); AstNode* null_expr = new(Z) LiteralNode(ident_pos, Instance::ZoneHandle(Z)); initialization = new(Z) StoreLocalNode( ident_pos, variable, null_expr); diff --git a/tests/standalone/debugger/local_variables_test.dart b/tests/standalone/debugger/local_variables_test.dart index cdd62faa819..b7871d431f9 100644 --- a/tests/standalone/debugger/local_variables_test.dart +++ b/tests/standalone/debugger/local_variables_test.dart @@ -29,10 +29,25 @@ test() { } } +test_no_init() { + if (true) { + var temp = 777; + } + if (true) { + var a; // Breakpoint + if (true) { + var s = 456; + print(s); + } + } +} + + main(List arguments) { if (RunScript(testScript, arguments)) return; print("Hello from debuggee"); test(); + test_no_init(); print("Hello again"); } @@ -44,6 +59,7 @@ var testScript = [ MatchFrame(0, "main"), // Should still be in "main". SetBreakpoint(15), // Set breakpoint in function foo. SetBreakpoint(24), // Set breakpoint in function test. + SetBreakpoint(37), // Set breakpoint in function test_no_init. Resume(), MatchFrames(["test", "main"]), AssertLocalsNotVisible(["a"]), // Here, a is not in scope yet. @@ -53,4 +69,9 @@ var testScript = [ Step(), MatchLocals({"y": "null"}), // Expect y initialized to null. Resume(), + MatchFrames(["test_no_init", "main"]), + AssertLocalsNotVisible(["a"]), // a is not in scope. + Step(), + MatchLocals({"a": "null"}), + Resume() ];