inference: register nested sessions for void compatible lambdas (IDEA-207070)

GitOrigin-RevId: 77f740e2754917b0053fcb79fb56e2b0c62436f4
This commit is contained in:
Anna Kozlova
2019-06-05 11:12:12 +03:00
committed by intellij-monorepo-bot
parent bff61142a8
commit 81a13b0fc0
3 changed files with 22 additions and 1 deletions
@@ -456,7 +456,7 @@ public class InferenceSession {
boolean addConstraint,
PsiSubstitutor initialSubstitutor) {
final PsiType interfaceReturnType = LambdaUtil.getFunctionalInterfaceReturnType(parameterType);
if (interfaceReturnType != null && !PsiType.VOID.equals(interfaceReturnType)) {
if (interfaceReturnType != null && (!PsiType.VOID.equals(interfaceReturnType) || !addConstraint)) {
final List<PsiExpression> returnExpressions = LambdaUtil.getReturnExpressions(lambdaExpression);
for (PsiExpression returnExpression : returnExpressions) {
processReturnExpression(additionalConstraints, ignoredConstraints, returnExpression, interfaceReturnType, addConstraint, initialSubstitutor);
@@ -0,0 +1,20 @@
import java.util.Arrays;
import java.util.List;
import java.util.function.Function;
class MyTest {
{
foo(() -> build(id(x -> x)));
}
static <I> I id(I i) {
return i;
}
static <K> void foo(Runnable e) {}
static <TT> List<TT> build(Function<String, TT> transformers) {
return null;
}
}
@@ -168,6 +168,7 @@ public class NewLambdaHighlightingTest extends LightDaemonAnalyzerTestCase {
public void testUnhandledExceptionInLambdaChain() { doTest(); }
public void testFunctionalBound() { doTest(); }
public void testValidFixesOnUnresolvedMethod() { doTest(); }
public void testPolyExpressionInVoidCompatibleLambdaReturn() { doTest(); }
private void doTest() {
IdeaTestUtil.setTestVersion(JavaSdkVersion.JDK_1_8, getModule(), getTestRootDisposable());