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

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

Issue 2800853005: Verify rethrow and parent's of variables. (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 | no next file » | 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..7ad90111131d19d245e1bb20c3b2fc4a759a7ea1 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;
@@ -272,10 +274,34 @@ class VerifyingVisitor extends RecursiveVisitor {
}
visitCatch(Catch node) {
+ bool savedinCatchBlock = inCatchBlock;
+ inCatchBlock = true;
visitWithLocalScope(node);
+ inCatchBlock = savedinCatchBlock;
asgerf 2017/04/07 08:52:52 Also save and set to false in visitFunctionNode.
ahe 2017/04/07 10:43:39 Good point. I know another file where I need to do
+ }
+
+ @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 | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698