From fb928f72c6fb4bfc5d02759934ee0d785543babf Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Tue, 13 Jun 2017 16:03:46 +0300 Subject: [PATCH] lambda inference: conditional expressions in returns (IDEA-174301) skip conditionals and parenthesis during find top expression --- .../InferenceSessionContainer.java | 3 +++ .../ConditionalExpressionInLambdaReturns.java | 20 +++++++++++++++++++ .../lambda/NewLambdaHighlightingTest.java | 1 + 3 files changed, 24 insertions(+) create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/newLambda/ConditionalExpressionInLambdaReturns.java diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSessionContainer.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSessionContainer.java index 6ccff5f705af..4ba0d7e723f1 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSessionContainer.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSessionContainer.java @@ -165,6 +165,9 @@ public class InferenceSessionContainer { gParent = returnContainer.getParent(); } } + if (gParent instanceof PsiConditionalExpression) { + gParent = PsiUtil.skipParenthesizedExprUp(gParent.getParent()); + } if (gParent instanceof PsiLambdaExpression) { final PsiCall call = PsiTreeUtil.getParentOfType(gParent, PsiCall.class); if (call != null) { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/newLambda/ConditionalExpressionInLambdaReturns.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/newLambda/ConditionalExpressionInLambdaReturns.java new file mode 100644 index 000000000000..b6fbd4521cd0 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/newLambda/ConditionalExpressionInLambdaReturns.java @@ -0,0 +1,20 @@ + +import java.util.function.Function; + +interface Container { + static Function> typeTester(Container c, final Container one) { + return funcWithString(input -> c.match(aa -> (true ? (zero()) : one))); + } + + static Function> funcWithString(Function> f) { + return null; + } + + default R match(Function f) { + return null; + } + + static Container zero() { + return null; + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/java/codeInsight/daemon/lambda/NewLambdaHighlightingTest.java b/java/java-tests/testSrc/com/intellij/java/codeInsight/daemon/lambda/NewLambdaHighlightingTest.java index 58c308524281..63d3a4cc149e 100644 --- a/java/java-tests/testSrc/com/intellij/java/codeInsight/daemon/lambda/NewLambdaHighlightingTest.java +++ b/java/java-tests/testSrc/com/intellij/java/codeInsight/daemon/lambda/NewLambdaHighlightingTest.java @@ -158,6 +158,7 @@ public class NewLambdaHighlightingTest extends LightDaemonAnalyzerTestCase { public void testIgnoreStandaloneExpressionsInLambdaReturnForNestedCalls() { doTest(); } public void testArrayNotAFunctionalInterface() { doTest(); } public void testRawSubstitutionForInterfaceMethod() { doTest(); } + public void testConditionalExpressionInLambdaReturns() { doTest(); } private void doTest() { IdeaTestUtil.setTestVersion(JavaSdkVersion.JDK_1_8, getModule(), getTestRootDisposable());