return value of try/catch/finally changed according to frontend changes
#KT-910 Fixed
This commit is contained in:
@@ -2672,8 +2672,6 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
|||||||
/*
|
/*
|
||||||
The "returned" value of try expression with no finally is either the last expression in the try block or the last expression in the catch block
|
The "returned" value of try expression with no finally is either the last expression in the try block or the last expression in the catch block
|
||||||
(or blocks).
|
(or blocks).
|
||||||
|
|
||||||
If finally block is present, its last expression is the value of try expression.
|
|
||||||
*/
|
*/
|
||||||
Label savedContinueLabel = continueLabel;
|
Label savedContinueLabel = continueLabel;
|
||||||
continueLabel = null;
|
continueLabel = null;
|
||||||
@@ -2689,14 +2687,11 @@ If finally block is present, its last expression is the value of try expression.
|
|||||||
Label tryStart = new Label();
|
Label tryStart = new Label();
|
||||||
v.mark(tryStart);
|
v.mark(tryStart);
|
||||||
v.nop(); // prevent verify error on empty try
|
v.nop(); // prevent verify error on empty try
|
||||||
if(finallyBlock == null)
|
gen(expression.getTryBlock(), expectedAsmType);
|
||||||
gen(expression.getTryBlock(), expectedAsmType);
|
|
||||||
else
|
|
||||||
gen(expression.getTryBlock(), Type.VOID_TYPE);
|
|
||||||
Label tryEnd = new Label();
|
Label tryEnd = new Label();
|
||||||
v.mark(tryEnd);
|
v.mark(tryEnd);
|
||||||
if (finallyBlock != null) {
|
if (finallyBlock != null) {
|
||||||
gen(finallyBlock.getFinalExpression(), expectedAsmType);
|
gen(finallyBlock.getFinalExpression(), Type.VOID_TYPE);
|
||||||
}
|
}
|
||||||
Label end = new Label();
|
Label end = new Label();
|
||||||
v.goTo(end); // TODO don't generate goto if there's no code following try/catch
|
v.goTo(end); // TODO don't generate goto if there's no code following try/catch
|
||||||
@@ -2711,12 +2706,12 @@ If finally block is present, its last expression is the value of try expression.
|
|||||||
int index = lookupLocal(descriptor);
|
int index = lookupLocal(descriptor);
|
||||||
v.store(index, descriptorType);
|
v.store(index, descriptorType);
|
||||||
|
|
||||||
gen(clause.getCatchBody(), finallyBlock != null ? Type.VOID_TYPE : expectedAsmType);
|
gen(clause.getCatchBody(), expectedAsmType);
|
||||||
|
|
||||||
myFrameMap.leave(descriptor);
|
myFrameMap.leave(descriptor);
|
||||||
|
|
||||||
if (finallyBlock != null) {
|
if (finallyBlock != null) {
|
||||||
gen(finallyBlock.getFinalExpression(), expectedAsmType);
|
gen(finallyBlock.getFinalExpression(), Type.VOID_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
v.goTo(end); // TODO don't generate goto if there's no code following try/catch
|
v.goTo(end); // TODO don't generate goto if there's no code following try/catch
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ fun box() : String {
|
|||||||
if(test2()) return "test2 failed"
|
if(test2()) return "test2 failed"
|
||||||
if(test3() != 2) return "test3 failed"
|
if(test3() != 2) return "test3 failed"
|
||||||
System.out?.println(test4())
|
System.out?.println(test4())
|
||||||
if(test4() != 3) return "test4 failed"
|
if(test4() != 0) return "test4 failed"
|
||||||
if(test5() != 11) return "test5 failed"
|
if(test5() != 11) return "test5 failed"
|
||||||
if(test6() != 10) return "test6 failed"
|
if(test6() != 10) return "test6 failed"
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
import java.util.Set
|
||||||
|
import java.util.HashSet
|
||||||
|
|
||||||
|
fun foo() : Int =
|
||||||
|
try {
|
||||||
|
2
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
"s"
|
||||||
|
}
|
||||||
|
|
||||||
|
fun bar(set : Set<Int>) : Set<Int> =
|
||||||
|
try {
|
||||||
|
set
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
set.add(42)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box() : String {
|
||||||
|
if (foo() != 2) return "fail 1"
|
||||||
|
val s = bar(HashSet<Int>())
|
||||||
|
return if (s.contains(42)) "OK" else "fail 2"
|
||||||
|
}
|
||||||
@@ -351,4 +351,9 @@ public class ControlStructuresTest extends CodegenTestCase {
|
|||||||
createEnvironmentWithMockJdkAndIdeaAnnotations(CompilerSpecialMode.JDK_HEADERS);
|
createEnvironmentWithMockJdkAndIdeaAnnotations(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("regressions/kt2062.kt");
|
blackBoxFile("regressions/kt2062.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testKt910() {
|
||||||
|
createEnvironmentWithMockJdkAndIdeaAnnotations(CompilerSpecialMode.JDK_HEADERS);
|
||||||
|
blackBoxFile("regressions/kt910.kt");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user