KT-3706 Inconsistent stack height in try catch finally in function

KT-4134 Incorrect bytecode is generated for

 #KT-3706 Fixed
 #KT-4134 Fixed
This commit is contained in:
Mikhael Bogdanov
2014-02-07 13:45:22 +04:00
parent 7b07b748cb
commit e0ca1abe4b
4 changed files with 58 additions and 1 deletions
@@ -1528,6 +1528,15 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
}
}
private boolean hasFinallyBLocks() {
for (BlockStackElement element : blockStackElements) {
if (element instanceof FinallyBlockStackElement) {
return true;
}
}
return false;
}
private void genFinallyBlockOrGoto(
@Nullable FinallyBlockStackElement finallyBlockStackElement,
@Nullable Label tryCatchBlockEnd
@@ -1566,7 +1575,14 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
JetExpression returnedExpression = expression.getReturnedExpression();
if (returnedExpression != null) {
gen(returnedExpression, returnType);
doFinallyOnReturn();
boolean hasFinallyBLocks = hasFinallyBLocks();
if (hasFinallyBLocks) {
int returnValIndex = myFrameMap.enterTemp(returnType);
StackValue.local(returnValIndex, returnType).store(returnType, v);
doFinallyOnReturn();
StackValue.local(returnValIndex, returnType).put(returnType, v);
myFrameMap.leaveTemp(returnType);
}
v.areturn(returnType);
}
else {