From fbf500d2d4f616edd250413a89a1426ef8aa6bc9 Mon Sep 17 00:00:00 2001 From: "Anna.Kozlova" Date: Wed, 26 Apr 2017 16:21:52 +0200 Subject: [PATCH] inference: skip standalone expressions in lambda returns (IDEA-171922) --- .../ExpressionCompatibilityConstraint.java | 3 +++ ...oneExpressionsInLambdaReturnForNestedCalls.java | 14 ++++++++++++++ .../daemon/lambda/NewLambdaHighlightingTest.java | 1 + 3 files changed, 18 insertions(+) create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/newLambda/IgnoreStandaloneExpressionsInLambdaReturnForNestedCalls.java diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/ExpressionCompatibilityConstraint.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/ExpressionCompatibilityConstraint.java index 4a6ef5c74700..86d104a2af2c 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/ExpressionCompatibilityConstraint.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/ExpressionCompatibilityConstraint.java @@ -129,6 +129,9 @@ public class ExpressionCompatibilityConstraint extends InputOutputConstraintForm PsiExpression expression, PsiType targetType, boolean registerErrorOnFailure) { + if (!PsiPolyExpressionUtil.isPolyExpression(expression)) { + return session; + } final PsiExpressionList argumentList = ((PsiCall)expression).getArgumentList(); if (argumentList != null) { final MethodCandidateInfo.CurrentCandidateProperties candidateProperties = MethodCandidateInfo.getCurrentMethod(argumentList); diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/newLambda/IgnoreStandaloneExpressionsInLambdaReturnForNestedCalls.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/newLambda/IgnoreStandaloneExpressionsInLambdaReturnForNestedCalls.java new file mode 100644 index 000000000000..0f57ae5cde70 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/newLambda/IgnoreStandaloneExpressionsInLambdaReturnForNestedCalls.java @@ -0,0 +1,14 @@ + +import java.util.ArrayList; +import java.util.Map; +import java.util.function.Function; +import java.util.stream.Collector; +import java.util.stream.Collectors; + + +class Foo { + private static void foo(final Function compose) { + Collector>> stringMapCollector = + Collectors.groupingBy(compose, Collector.of(() -> new ArrayList(), null, null, s -> new ArrayList<>(s))); + } +} \ No newline at end of file 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 a0fa43720372..2edb5879a2b0 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 @@ -155,6 +155,7 @@ public class NewLambdaHighlightingTest extends LightDaemonAnalyzerTestCase { public void testGroundTargetTypeWhenAbstractMethodInSuperclass() { doTest(); } public void testNestedLambdasWithInferenceOfReturnTypeInTheLatestLambda() { doTest(); } public void testCapturedWildcardNotOpenedDuringInference() { doTest(); } + public void testIgnoreStandaloneExpressionsInLambdaReturnForNestedCalls() { doTest(); } private void doTest() { IdeaTestUtil.setTestVersion(JavaSdkVersion.JDK_1_8, getModule(), getTestRootDisposable());