Lambda inlining: handle try-catches in lambda

This commit is contained in:
Tagir Valeev
2017-07-27 11:56:56 +07:00
parent 890a2c90eb
commit 7d7828f932
2 changed files with 19 additions and 0 deletions
@@ -1865,6 +1865,8 @@ public class ControlFlowAnalyzer extends JavaElementVisitor {
PsiLambdaExpression oldLambda = myAnalyzer.myLambdaExpression;
myAnalyzer.myLambdaExpression = lambda;
myAnalyzer.startElement(lambda);
// Transfer value is pushed to avoid emptying stack beyond this point
push(getFactory().controlTransfer(ReturnTransfer.INSTANCE, myAnalyzer.myTrapStack));
try {
PsiElement body = lambda.getBody();
Objects.requireNonNull(body).accept(myAnalyzer);
@@ -1876,6 +1878,8 @@ public class ControlFlowAnalyzer extends JavaElementVisitor {
}
}
finally {
// Pop transfer value (which is second value in stack now)
splice(2, 0);
myAnalyzer.finishElement(lambda);
myAnalyzer.myLambdaExpression = oldLambda;
}
@@ -12,4 +12,19 @@ public class LambdaInlining {
System.out.println("oops");
}
}
void testLambdaTryCatch() {
int x = ((IntSupplier)(() -> {
try {
return Math.random() > 0.5 ? 2 : 3;
}
catch (Exception ex) {
}
return 1;
})).getAsInt();
if(<warning descr="Condition 'x == 0' is always 'false'">x == 0</warning>) {
System.out.println("oops");
}
}
}