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

Unified Diff: pkg/kernel/lib/verifier.dart

Issue 2800853005: Verify rethrow and parent's of variables. (Closed)
Patch Set: Update status files. 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 | « pkg/front_end/test/fasta/compile.status ('k') | pkg/pkg.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/kernel/lib/verifier.dart
diff --git a/pkg/kernel/lib/verifier.dart b/pkg/kernel/lib/verifier.dart
index 5de5288050a1f34662a64a0b0d64b456eb98626d..c518a6566f3f562eeb19d198f6e568c89256dc47 100644
--- a/pkg/kernel/lib/verifier.dart
+++ b/pkg/kernel/lib/verifier.dart
@@ -51,6 +51,8 @@ class VerifyingVisitor extends RecursiveVisitor {
/// attempt to validate constructor initializers.
bool isOutline = false;
+ bool inCatchBlock = false;
+
Member currentMember;
Class currentClass;
TreeNode currentParent;
@@ -234,7 +236,10 @@ class VerifyingVisitor extends RecursiveVisitor {
visitFunctionNode(FunctionNode node) {
declareTypeParameters(node.typeParameters);
+ bool savedInCatchBlock = inCatchBlock;
+ inCatchBlock = false;
visitWithLocalScope(node);
+ inCatchBlock = savedInCatchBlock;
undeclareTypeParameters(node.typeParameters);
}
@@ -272,10 +277,34 @@ class VerifyingVisitor extends RecursiveVisitor {
}
visitCatch(Catch node) {
+ bool savedInCatchBlock = inCatchBlock;
+ inCatchBlock = true;
visitWithLocalScope(node);
+ inCatchBlock = savedInCatchBlock;
+ }
+
+ @override
+ visitRethrow(Rethrow node) {
+ if (!inCatchBlock) {
+ problem(node, "Rethrow must be inside a Catch block.");
+ }
}
visitVariableDeclaration(VariableDeclaration node) {
+ var parent = node.parent;
+ if (parent is! Block &&
+ !(parent is Catch && parent.body != node) &&
+ !(parent is FunctionNode && parent.body != node) &&
+ parent is! FunctionDeclaration &&
+ !(parent is ForStatement && parent.body != node) &&
+ !(parent is ForInStatement && parent.body != node) &&
+ parent is! Let &&
+ parent is! LocalInitializer) {
+ problem(
+ node,
+ "VariableDeclaration must be a direct child of a Block, "
+ "not ${parent.runtimeType}.");
+ }
visitChildren(node);
declareVariable(node);
}
« no previous file with comments | « pkg/front_end/test/fasta/compile.status ('k') | pkg/pkg.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698