VM: Fix a bug with local variable values when breaking at a variable declaration.

This fixes the case When breaking at a declaration 'var a;'

BUG=dartbug.com/22353
R=hausner@google.com

Review URL: https://codereview.chromium.org//936283005

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@43882 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
fschneider@google.com 2015-02-19 17:11:07 +00:00
parent 6bb78fd867
commit 2442d5e047
2 changed files with 23 additions and 2 deletions

View file

@ -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);

View file

@ -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<String> 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()
];