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

Unified Diff: compiler/java/com/google/dart/compiler/type/TypeAnalyzer.java

Issue 8247007: Detect re-throws outside of a catch block. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 9 years, 2 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
Index: compiler/java/com/google/dart/compiler/type/TypeAnalyzer.java
===================================================================
--- compiler/java/com/google/dart/compiler/type/TypeAnalyzer.java (revision 375)
+++ compiler/java/com/google/dart/compiler/type/TypeAnalyzer.java (working copy)
@@ -169,6 +169,12 @@
private final Type nullType;
private final InterfaceType functionType;
+ /**
+ * Keeps track of the number of nested catches, used to detect re-throws
+ * outside of any catch block.
+ */
+ private int catchDepth = 0;
+
Analyzer(DartCompilerContext context, CoreTypeProvider typeProvider,
ConcurrentHashMap<ClassElement, List<Element>> unimplementedElements,
Set<ClassElement> diagnosedAbstractClasses) {
@@ -1125,15 +1131,21 @@
@Override
public Type visitThrowStatement(DartThrowStatement node) {
+ if (catchDepth == 0 && node.getException() == null) {
+ context.compilationError(new DartCompilationError(node,
+ DartCompilerErrorCode.RETHROW_NOT_IN_CATCH));
+ }
return typeAsVoid(node);
}
@Override
public Type visitCatchBlock(DartCatchBlock node) {
+ ++catchDepth;
typeOf(node.getException());
// TODO(karlklose) Check type of stack trace variable.
typeOf(node.getStackTrace());
typeOf(node.getBlock());
+ --catchDepth;
return voidType;
}

Powered by Google App Engine
This is Rietveld 408576698