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

Unified Diff: runtime/vm/parser.cc

Issue 60943003: Fix scoping of catch clause variables (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 | « no previous file | tests/language/try_catch_test.dart » ('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 29929)
+++ runtime/vm/parser.cc (working copy)
@@ -6875,8 +6875,7 @@
// Parse the individual catch handler code and add an unconditional JUMP
// to the end of the try block.
- ExpectToken(Token::kLBRACE);
- OpenBlock();
+ OpenBlock(); // Block for the exception and stack trace variables.
AddCatchParametersToScope(&exception_param, &stack_trace_param,
current_block_->scope);
@@ -6906,11 +6905,13 @@
no_args));
}
- ParseStatementSequence(); // Parse the catch handler code.
- current_block_->statements->Add(
+ // Parse the catch handler code.
+ if (CurrentToken() != Token::kLBRACE) {
+ ErrorMsg("'{' expected");
+ }
+ SequenceNode* catch_block = ParseNestedStatement(false, NULL);
+ catch_block->Add(
new JumpNode(catch_pos, Token::kCONTINUE, end_catch_label));
- SequenceNode* catch_handler = CloseBlock();
- ExpectToken(Token::kRBRACE);
const bool is_bad_type = exception_param.type.IsMalformed() ||
exception_param.type.IsMalbounded();
@@ -6931,7 +6932,7 @@
AstNode* type_cond_expr = new ComparisonNode(
catch_pos, Token::kIS, exception_value, exception_type);
current_block_->statements->Add(
- new IfNode(catch_pos, type_cond_expr, catch_handler, NULL));
+ new IfNode(catch_pos, type_cond_expr, catch_block, NULL));
// Do not add uninstantiated types (e.g. type parameter T or generic
// type List<T>), since the debugger won't be able to instantiate it
@@ -6950,13 +6951,16 @@
}
// No exception type exists in the catch specifier so execute the
// catch handler code unconditionally.
- current_block_->statements->Add(catch_handler);
+ current_block_->statements->Add(catch_block);
generic_catch_seen = true;
// This catch clause will handle all exceptions. We can safely forget
// all previous catch clause types.
handler_types.SetLength(0);
handler_types.Add(exception_param.type);
}
+ // Add this individual catch handler to the catch handlers list.
+ SequenceNode* catch_clause = CloseBlock();
+ current_block_->statements->Add(catch_clause);
}
SequenceNode* catch_handler_list = CloseBlock();
TryBlocks* inner_try_block = PopTryBlock();
« no previous file with comments | « no previous file | tests/language/try_catch_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698