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

Unified Diff: pkg/front_end/lib/src/fasta/kernel/body_builder.dart

Issue 2802203002: Handle bad rethrows. (Closed)
Patch Set: Created 3 years, 8 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
« no previous file with comments | « no previous file | tests/co19/co19-kernel.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/front_end/lib/src/fasta/kernel/body_builder.dart
diff --git a/pkg/front_end/lib/src/fasta/kernel/body_builder.dart b/pkg/front_end/lib/src/fasta/kernel/body_builder.dart
index ca3b4ed4d07b3e91a73e354240ccfffbb98c2c34..489a6bc10bddd4c2a254bd0045ac6a38a1a31b50 100644
--- a/pkg/front_end/lib/src/fasta/kernel/body_builder.dart
+++ b/pkg/front_end/lib/src/fasta/kernel/body_builder.dart
@@ -85,6 +85,8 @@ class BodyBuilder extends ScopeListener<JumpTarget> implements BuilderHelper {
bool inCatchClause = false;
+ bool inCatchBlock = false;
+
int functionNestingLevel = 0;
Statement compileTimeErrorInTry;
@@ -1518,12 +1520,15 @@ class BodyBuilder extends ScopeListener<JumpTarget> implements BuilderHelper {
void endCatchClause(Token token) {
debugEvent("CatchClause");
inCatchClause = false;
+ push(inCatchBlock);
+ inCatchBlock = true;
}
@override
void handleCatchBlock(Token onKeyword, Token catchKeyword) {
debugEvent("CatchBlock");
Block body = pop();
+ inCatchBlock = pop();
if (catchKeyword != null) {
exitLocalScope();
}
@@ -1910,11 +1915,14 @@ class BodyBuilder extends ScopeListener<JumpTarget> implements BuilderHelper {
functionNestingLevel++;
push(switchScope ?? NullValue.SwitchScope);
switchScope = null;
+ push(inCatchBlock);
+ inCatchBlock = false;
}
void exitFunction() {
debugEvent("exitFunction");
functionNestingLevel--;
+ inCatchBlock = pop();
switchScope = pop();
}
@@ -2100,8 +2108,14 @@ class BodyBuilder extends ScopeListener<JumpTarget> implements BuilderHelper {
@override
void endRethrowStatement(Token throwToken, Token endToken) {
debugEvent("RethrowStatement");
- push(new ExpressionStatement(
- new Rethrow()..fileOffset = throwToken.charOffset));
+ if (inCatchBlock) {
+ push(new ExpressionStatement(
+ new Rethrow()..fileOffset = throwToken.charOffset));
+ } else {
+ push(buildCompileTimeErrorStatement(
+ "'rethrow' can only be used in catch clauses.",
+ throwToken.charOffset));
+ }
}
@override
« no previous file with comments | « no previous file | tests/co19/co19-kernel.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698