Skip to content

Commit

Permalink
Retain data flow info after try-finally
Browse files Browse the repository at this point in the history
  • Loading branch information
udalov committed Nov 16, 2012
1 parent d629fe2 commit ef3e380
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
Expand Up @@ -425,18 +425,22 @@ public JetTypeInfo visitTryExpression(JetTryExpression expression, ExpressionTyp
}
}
}

DataFlowInfo dataFlowInfo = context.dataFlowInfo;
if (finallyBlock != null) {
facade.getTypeInfo(finallyBlock.getFinalExpression(), context.replaceExpectedType(TypeUtils.NO_EXPECTED_TYPE));
dataFlowInfo = facade.getTypeInfo(finallyBlock.getFinalExpression(),
context.replaceExpectedType(TypeUtils.NO_EXPECTED_TYPE)).getDataFlowInfo();
}

JetType type = facade.getTypeInfo(tryBlock, context).getType();
if (type != null) {
types.add(type);
}
if (types.isEmpty()) {
return JetTypeInfo.create(null, context.dataFlowInfo);
return JetTypeInfo.create(null, dataFlowInfo);
}
else {
return JetTypeInfo.create(CommonSupertypes.commonSupertype(types), context.dataFlowInfo);
return JetTypeInfo.create(CommonSupertypes.commonSupertype(types), dataFlowInfo);
}
}

Expand Down
@@ -0,0 +1,19 @@
fun tryFinally(x: Int?) {
try {
} finally {
x!!
}
x : Int
}

fun tryCatchFinally(x: Int?) {
try {
x!!
} catch (e: Exception) {
x!!
} finally {
<!TYPE_MISMATCH!>x<!> : Int
x!!
}
x : Int
}
Expand Up @@ -1296,6 +1296,11 @@ public void testTryCatch() throws Exception {
doTest("compiler/testData/diagnostics/tests/dataFlowInfoTraversal/TryCatch.kt");
}

@TestMetadata("TryFinally.kt")
public void testTryFinally() throws Exception {
doTest("compiler/testData/diagnostics/tests/dataFlowInfoTraversal/TryFinally.kt");
}

@TestMetadata("UnaryExpression.kt")
public void testUnaryExpression() throws Exception {
doTest("compiler/testData/diagnostics/tests/dataFlowInfoTraversal/UnaryExpression.kt");
Expand Down

0 comments on commit ef3e380

Please sign in to comment.