From 344379d2f443f336702f288f0304443a9ec97108 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Thu, 12 Feb 2015 21:12:10 +0100 Subject: [PATCH] lambda: accept? inference variables as target type for lambda expression during lambda constraint reduction (IDEA-136435) --- .../LambdaExpressionCompatibilityConstraint.java | 3 +++ ...NestedLambdaWithInferenceVariableAsTargetType.java | 11 +++++++++++ .../daemon/lambda/NewLambdaHighlightingTest.java | 4 ++++ 3 files changed, 18 insertions(+) create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/newLambda/NestedLambdaWithInferenceVariableAsTargetType.java diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/LambdaExpressionCompatibilityConstraint.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/LambdaExpressionCompatibilityConstraint.java index 28f407f2efb0..9a5c2fa84e3c 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/LambdaExpressionCompatibilityConstraint.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/LambdaExpressionCompatibilityConstraint.java @@ -22,6 +22,9 @@ public class LambdaExpressionCompatibilityConstraint implements ConstraintFormul @Override public boolean reduce(InferenceSession session, List constraints) { + if (session.getInferenceVariable(myT) != null) { + return true; + } if (!LambdaUtil.isFunctionalType(myT)) { return false; } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/newLambda/NestedLambdaWithInferenceVariableAsTargetType.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/newLambda/NestedLambdaWithInferenceVariableAsTargetType.java new file mode 100644 index 000000000000..16d6da06f529 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/newLambda/NestedLambdaWithInferenceVariableAsTargetType.java @@ -0,0 +1,11 @@ +import java.util.function.Supplier; + +class Test { + { + Supplier x = foo(() -> () -> {}); + } + + static Supplier foo(Supplier delegate) { + return null; + } +} diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/NewLambdaHighlightingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/NewLambdaHighlightingTest.java index cf5189bb567c..72b67b4d5440 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/NewLambdaHighlightingTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/NewLambdaHighlightingTest.java @@ -99,6 +99,10 @@ public class NewLambdaHighlightingTest extends LightDaemonAnalyzerTestCase { doTest(); } + public void testNestedLambdaWithInferenceVariableAsTargetType() throws Exception { + doTest(); + } + public void testIDEA127596() throws Exception { doTest(); }