added edge from try start to error through finally block
KT-2845 Wrong cf-analysys for variable initialization in try..finally #KT-2845 fixed todo: some errors now are reported for several times (each time when analyzing finally block)
This commit is contained in:
@@ -371,6 +371,11 @@ public class JetControlFlowProcessor {
|
||||
onException = builder.createUnboundLabel();
|
||||
builder.nondeterministicJump(onException);
|
||||
}
|
||||
Label onExceptionToFinallyBlock = null;
|
||||
if (finallyBlock != null) {
|
||||
onExceptionToFinallyBlock = builder.createUnboundLabel();
|
||||
builder.nondeterministicJump(onExceptionToFinallyBlock);
|
||||
}
|
||||
value(expression.getTryBlock(), inCondition);
|
||||
|
||||
if (hasCatches) {
|
||||
@@ -414,6 +419,14 @@ public class JetControlFlowProcessor {
|
||||
|
||||
if (finallyBlock != null) {
|
||||
builder.exitTryFinally();
|
||||
|
||||
Label skipFinallyToErrorBlock = builder.createUnboundLabel();
|
||||
builder.jump(skipFinallyToErrorBlock);
|
||||
builder.bindLabel(onExceptionToFinallyBlock);
|
||||
value(finallyBlock.getFinalExpression(), inCondition);
|
||||
builder.jumpToError();
|
||||
builder.bindLabel(skipFinallyToErrorBlock);
|
||||
|
||||
value(finallyBlock.getFinalExpression(), inCondition);
|
||||
}
|
||||
builder.stopAllowDead();
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
//KT-2845 Wrong cf-analysys for variable initialization in try..finally
|
||||
package h
|
||||
|
||||
import java.util.ArrayList
|
||||
|
||||
private fun doTest() : Int {
|
||||
var list : MutableList<Int>? ;
|
||||
try {
|
||||
list = ArrayList()
|
||||
list?.add(3)
|
||||
return 0 ;
|
||||
}
|
||||
finally {
|
||||
if(<!UNINITIALIZED_VARIABLE!>list<!> != null) { // Must be an ERROR
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -894,6 +894,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage
|
||||
doTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/kt2330.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt2845.kt")
|
||||
public void testKt2845() throws Exception {
|
||||
doTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/kt2845.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt510.kt")
|
||||
public void testKt510() throws Exception {
|
||||
doTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/kt510.kt");
|
||||
|
||||
Reference in New Issue
Block a user