diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java index 0aa7afd83c93..faad4dd6c1ec 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java @@ -15,6 +15,7 @@ */ package com.intellij.psi.impl.source.resolve.graphInference; +import com.intellij.codeInsight.PsiEquivalenceUtil; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.Key; @@ -1640,6 +1641,11 @@ public class InferenceSession { } } + //no additional constraints for array creation + if (PsiEquivalenceUtil.areElementsEquivalent(containingClass, JavaPsiFacade.getElementFactory(reference.getProject()).getArrayClass(PsiUtil.getLanguageLevel(reference)))) { + return null; + } + final PsiType qType = JavaPsiFacade.getElementFactory(method.getProject()).createType(containingClass, psiSubstitutor); addConstraint(new TypeCompatibilityConstraint(substituteWithInferenceVariables(qType), pType)); diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/MethodReferenceResolver.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/MethodReferenceResolver.java index 74f6eb778fd6..96f6000d3e0f 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/MethodReferenceResolver.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/MethodReferenceResolver.java @@ -17,6 +17,7 @@ package com.intellij.psi.impl.source.tree.java; import com.intellij.codeInsight.PsiEquivalenceUtil; import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.*; import com.intellij.psi.impl.source.resolve.ParameterTypeInferencePolicy; import com.intellij.psi.impl.source.resolve.ResolveCache; @@ -124,6 +125,10 @@ public class MethodReferenceResolver implements ResolveCache.PolyVariantContextR } if (!session.repeatInferencePhases()) { + List errorMessages = session.getIncompatibleErrorMessages(); + if (errorMessages != null) { + setApplicabilityError(StringUtil.join(errorMessages, "\n")); + } return substitutor; } @@ -140,6 +145,7 @@ public class MethodReferenceResolver implements ResolveCache.PolyVariantContextR @Override public boolean isApplicable() { if (signature == null) return false; + if (getInferenceErrorMessageAssumeAlreadyComputed() != null) return false; final PsiType[] argTypes = signature.getParameterTypes(); boolean hasReceiver = PsiMethodReferenceUtil.isSecondSearchPossible(argTypes, qualifierResolveResult, reference); diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/methodRef/AccessModifiers.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/methodRef/AccessModifiers.java index da4b5496871e..b5b406b59a26 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/methodRef/AccessModifiers.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/methodRef/AccessModifiers.java @@ -24,7 +24,7 @@ class AlienTest { static { IInt i1 = MyTest::abracadabra; - IInt i2 = MyTest::foo; + IInt i2 = MyTest::foo; IInt i3 = MyTest::bar; IIntInt i4 = MyTest::bar; IInt i5 = MyTest::baz; diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/methodRef/Ambiguity.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/methodRef/Ambiguity.java index 9796021e9ed8..43a177f60ebc 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/methodRef/Ambiguity.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/methodRef/Ambiguity.java @@ -47,7 +47,7 @@ class MyTest1 { } { - Bar1 b1 = MyTest2 :: foo; + Bar1 b1 = MyTest2 :: foo; bar(MyTest1 :: foo); } } @@ -73,7 +73,7 @@ class MyTest2 { }*/ { - Bar1 b1 = MyTest2 :: foo; + Bar1 b1 = MyTest2 :: foo; bar(MyTest2 :: foo); } } @@ -99,8 +99,8 @@ class MyTest3 { } { - Bar1 b1 = MyTest2 :: foo; - bar(MyTest3 :: foo); + Bar1 b1 = MyTest2 :: foo; + bar(MyTest3 :: foo); } } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/methodRef/Assignability.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/methodRef/Assignability.java index b9902fa92d55..b4db64c282db 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/methodRef/Assignability.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/methodRef/Assignability.java @@ -2,7 +2,7 @@ class Test { { Runnable b = Test :: length; Comparable c = Test :: length; - Comparable c1 = Test :: length; + Comparable c1 = Test :: length; } public static Integer length(String s) { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/methodRef/Varargs.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/methodRef/Varargs.java index 4f69a80fcddc..1504477c0c19 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/methodRef/Varargs.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/methodRef/Varargs.java @@ -49,7 +49,7 @@ class MyTest { static { I1 i1 = MyTest::static_1; I1 i2 = MyTest::static_2; - I1 i3 = MyTest::static_3; + I1 i3 = MyTest::static_3; I1 i4 = MyTest::static_4; } @@ -62,7 +62,7 @@ class MyTest { I1 i1 = this::_1; I1 i2 = this::_2; - I1 i3 = this::_3; + I1 i3 = this::_3; I1 i4 = this::_4; I2 i21 = MyTest::m1; diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/newMethodRef/ApplicabilityConflictMessage.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/newMethodRef/ApplicabilityConflictMessage.java index 207e21a5e908..0e0cbc1576d0 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/newMethodRef/ApplicabilityConflictMessage.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/newMethodRef/ApplicabilityConflictMessage.java @@ -5,7 +5,7 @@ class A { public static void main(String[] args) { B q = new B<>(); - Func x = q::foo; + Func x = q::foo; x.invoke(""); } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/newMethodRef/CapturedTypesOfImplicitParameterTypes.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/newMethodRef/CapturedTypesOfImplicitParameterTypes.java index 1abedc8e0c2d..0da62b3506da 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/newMethodRef/CapturedTypesOfImplicitParameterTypes.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/newMethodRef/CapturedTypesOfImplicitParameterTypes.java @@ -7,7 +7,7 @@ interface B { class Test { public static void test() { - method1(Test::method2); + method1(Test::method2); } static void method1(B> arg) { } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/newMethodRef/DistinguishCapturedWildcardsByDifferentParameters.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/newMethodRef/DistinguishCapturedWildcardsByDifferentParameters.java index ab2c776d7fe9..837925b32b67 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/newMethodRef/DistinguishCapturedWildcardsByDifferentParameters.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/newMethodRef/DistinguishCapturedWildcardsByDifferentParameters.java @@ -4,7 +4,7 @@ import java.util.function.Predicate; class MyTest { { - BiConsumer, Predicate> or = MyTest::or; + BiConsumer, Predicate> or = MyTest::or; } private static void or(Predicate left, Predicate right) {} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/newMethodRef/HighlightReferenceWhenContradictBoundsAreInferred.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/newMethodRef/HighlightReferenceWhenContradictBoundsAreInferred.java index 0814550220a9..591df9c81ee8 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/newMethodRef/HighlightReferenceWhenContradictBoundsAreInferred.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/newMethodRef/HighlightReferenceWhenContradictBoundsAreInferred.java @@ -29,14 +29,14 @@ class Test { static void meth4(I3 s) { } static { - meth1(Foo::new); + meth1(Foo::new); meth2(Foo::new); - meth3(Foo::new); + meth3(Foo::new); meth4(Foo::new); - meth1(Test::foo); + meth1(Test::foo); meth2(Test::foo); - meth3(Test::foo); + meth3(Test::foo); meth4(Test::foo); } @@ -55,8 +55,8 @@ class Test { } void test() { - II1 i1 = this::fooInstance; + II1 i1 = this::fooInstance; II2 i2 = this::fooInstance; - II3 i3 = this::fooInstance; + II3 i3 = this::fooInstance; } } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/newMethodRef/MethodReferenceSwallowedErrors.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/newMethodRef/MethodReferenceSwallowedErrors.java new file mode 100644 index 000000000000..9364b4d9b35c --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/newMethodRef/MethodReferenceSwallowedErrors.java @@ -0,0 +1,45 @@ + +import java.util.function.Supplier; +import java.util.function.BiFunction; +import java.util.function.Function; + +interface Regression { + , FB extends Functor> FT apply( + Function fn, S s); + + static Regression regression(Function getter, + BiFunction setter) { + return new Regression() { + @Override + @SuppressWarnings("unchecked") + public , FB extends Functor> FT apply( + Function fn, + S s) { + return null; //doesn't matter + } + }; + } + + @SuppressWarnings("unchecked") + static Simple simple(Function getter, + BiFunction setter) { + return regression(getter, setter)::apply; // java9 fails to compile this line + } + + interface Functor { + } + + @FunctionalInterface + interface Simple extends Regression { + } +} + +interface SimplifiedTest { + > FB apply(Supplier fn); + + static SimplifiedTest simple(final SimplifiedTest regression) { + return regression::apply; + } + + interface Functor { } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/newMethodRef/NonExactMethodReferenceOnRawClassType.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/newMethodRef/NonExactMethodReferenceOnRawClassType.java index 05df39960a0c..3188ca0df880 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/newMethodRef/NonExactMethodReferenceOnRawClassType.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/newMethodRef/NonExactMethodReferenceOnRawClassType.java @@ -4,7 +4,7 @@ class InlineRef { void foo(Consumer f) {} void bar(){ - foo(Descriptor::getName); + foo(Descriptor::getName); } } diff --git a/java/java-tests/testSrc/com/intellij/java/codeInsight/daemon/lambda/NewMethodRefHighlightingTest.java b/java/java-tests/testSrc/com/intellij/java/codeInsight/daemon/lambda/NewMethodRefHighlightingTest.java index e0bf25a2ebe6..13de648eb7a3 100644 --- a/java/java-tests/testSrc/com/intellij/java/codeInsight/daemon/lambda/NewMethodRefHighlightingTest.java +++ b/java/java-tests/testSrc/com/intellij/java/codeInsight/daemon/lambda/NewMethodRefHighlightingTest.java @@ -177,6 +177,7 @@ public class NewMethodRefHighlightingTest extends LightDaemonAnalyzerTestCase { public void testConstructorRefOnClassWithRecursiveTypeParameter() { doTest(); } public void testWildcardInCheckedCompatibilityConstraints() { doTest(); } public void testConstructorReferenceWithVarargsParameters() { doTest(); } + public void testMethodReferenceSwallowedErrors() { doTest(); } public void testPreferErrorOnTopLevelToFailedSubstitutorOnNestedLevel() { doTest(); }