method reference: don't start containing class parameter type inference for receiver-reference; corresponding substitutor should be already known (IDEA-146604; IDEA-147223)

This commit is contained in:
Anna Kozlova
2015-11-03 14:56:46 +01:00
parent d4f0daa29a
commit 2d21b7777e
4 changed files with 26 additions and 3 deletions

View File

@@ -1330,8 +1330,6 @@ public class InferenceSession {
}
}
else if (PsiMethodReferenceUtil.isResolvedBySecondSearch(reference, signature, varargs, isStatic, parameters.length)) { //instance methods
initBounds(containingClass.getTypeParameters());
final PsiType pType = signature.getParameterTypes()[0];
// 15.13.1 If the ReferenceType is a raw type, and there exists a parameterization of this type, T, that is a supertype of P1,
@@ -1347,6 +1345,7 @@ public class InferenceSession {
return receiverSubstitutor;
}
}
mySiteSubstitutor = mySiteSubstitutor.putAll(receiverSubstitutor);
psiSubstitutor = receiverSubstitutor;
}
}

View File

@@ -0,0 +1,20 @@
import java.util.Arrays;
import java.util.function.BinaryOperator;
import java.util.function.Predicate;
import java.util.stream.Stream;
class C {
private static void foo(final Stream<Predicate<Boolean>> stream) {
BinaryOperator<Predicate<Boolean>> bo = Predicate::and;
Predicate<Boolean> notWorking = stream.reduce(Predicate::and).orElse(t -> true);
}
public static void bar(Stream<E> stream) {
Object[] array = stream
.sorted(Enum::compareTo)
.toArray();
System.out.println("array = " + Arrays.toString(array));
}
enum E {;}
}

View File

@@ -16,7 +16,7 @@ class MyTest<T> {
return this;
}
public Builder<E> add(E... elements) {
public Builder<E> add(E... <warning descr="Parameter 'elements' is never used">elements</warning>) {
return this;
}
}

View File

@@ -442,6 +442,10 @@ public class NewMethodRefHighlightingTest extends LightDaemonAnalyzerTestCase {
doTest();
}
public void testContainingClassTypeParametersShouldNotBeInferredDuringMethodReferenceProcessing() throws Exception {
doTest();
}
private void doTest() {
doTest(false);
}