From c719482b06a246b12fe461eeaabcaf07e5185bc2 Mon Sep 17 00:00:00 2001 From: "Anna.Kozlova" Date: Thu, 9 Mar 2017 15:02:09 +0100 Subject: [PATCH] pull up inference errors when current call has no type parameters (IDEA-169316) --- .../com/intellij/psi/infos/MethodCandidateInfo.java | 9 ++++++--- .../diamond/DiamondInsideOverloadedThisReference.java | 11 +++++++++++ .../daemon/lambda/Diamond8HighlightingTest.java | 4 ++++ 3 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/diamond/DiamondInsideOverloadedThisReference.java diff --git a/java/java-psi-api/src/com/intellij/psi/infos/MethodCandidateInfo.java b/java/java-psi-api/src/com/intellij/psi/infos/MethodCandidateInfo.java index c46d8f8abcb0..6758e9953a1a 100644 --- a/java/java-psi-api/src/com/intellij/psi/infos/MethodCandidateInfo.java +++ b/java/java-psi-api/src/com/intellij/psi/infos/MethodCandidateInfo.java @@ -111,7 +111,7 @@ public class MethodCandidateInfo extends CandidateInfo{ public int getPertinentApplicabilityLevel() { if (myPertinentApplicabilityLevel == 0) { myPertinentApplicabilityLevel = getPertinentApplicabilityLevelInner(); - pullInferenceErrorMessagesFromSubexpressions(); + myPertinentApplicabilityLevel = pullInferenceErrorMessagesFromSubexpressions(); } return myPertinentApplicabilityLevel; } @@ -474,8 +474,9 @@ public class MethodCandidateInfo extends CandidateInfo{ return errorMessage; } - private void pullInferenceErrorMessagesFromSubexpressions() { - if (myPertinentApplicabilityLevel == ApplicabilityLevel.NOT_APPLICABLE && myArgumentList instanceof PsiExpressionList) { + private int pullInferenceErrorMessagesFromSubexpressions() { + if (myArgumentList instanceof PsiExpressionList && + (myPertinentApplicabilityLevel == ApplicabilityLevel.NOT_APPLICABLE || !isToInferApplicability())) { String errorMessage = null; for (PsiExpression expression : ((PsiExpressionList)myArgumentList).getExpressions()) { final String message = clearErrorMessageInSubexpressions(expression); @@ -485,8 +486,10 @@ public class MethodCandidateInfo extends CandidateInfo{ } if (errorMessage != null) { setInferenceError(errorMessage); + return ApplicabilityLevel.NOT_APPLICABLE; } } + return myPertinentApplicabilityLevel; } private static String clearErrorMessageInSubexpressions(PsiExpression expression) { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/diamond/DiamondInsideOverloadedThisReference.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/diamond/DiamondInsideOverloadedThisReference.java new file mode 100644 index 000000000000..e4d8d1c3536e --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/diamond/DiamondInsideOverloadedThisReference.java @@ -0,0 +1,11 @@ + +class A {} +class B extends A {} + +class X { + public X(A b1) { + this(new B<>()); + } + + public X(B b2) {} +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/Diamond8HighlightingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/Diamond8HighlightingTest.java index e1e7278ffb77..3827a0bda3ed 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/Diamond8HighlightingTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/Diamond8HighlightingTest.java @@ -81,6 +81,10 @@ public class Diamond8HighlightingTest extends LightDaemonAnalyzerTestCase { doTest(); } + public void testDiamondInsideOverloadedThisReference() throws Exception { + doTest(); + } + private void doTest() throws Exception { doTest(BASE_PATH + "/" + getTestName(false) + ".java", false, false); }