mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-05-06 05:10:22 +07:00
new inference: method reference constraint for the case of return type depends on type params (IDEA-122100)
This commit is contained in:
@@ -156,12 +156,18 @@ public class PsiMethodReferenceCompatibilityConstraint implements ConstraintForm
|
||||
session.initBounds(containingClass.getTypeParameters());
|
||||
}
|
||||
|
||||
//if i) the method reference elides NonWildTypeArguments,
|
||||
// ii) the compile-time declaration is a generic method, and
|
||||
// iii) the return type of the compile-time declaration mentions at least one of the method's type parameters;
|
||||
if (typeParameters.length == 0 && method.getTypeParameters().length > 0) {
|
||||
final PsiClass interfaceClass = classResolveResult.getElement();
|
||||
LOG.assertTrue(interfaceClass != null);
|
||||
if (PsiPolyExpressionUtil.mentionsTypeParameters(referencedMethodReturnType,
|
||||
ContainerUtil.newHashSet(method.getTypeParameters()))) {
|
||||
constraints.add(new TypeCompatibilityConstraint(referencedMethodReturnType, returnType));
|
||||
//the constraint reduces to the bound set B3 which would be used to determine the method reference's invocation type
|
||||
//when targeting the return type of the function type, as defined in 18.5.2.
|
||||
//as there is no parameters, only constraint for return types is left. Here you are:
|
||||
session.registerConstraints(referencedMethodReturnType, returnType);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
|
||||
class InferenceExample<E> {
|
||||
public <Output> List<Output> convertAll(Function<E, Output> converter) {
|
||||
return invoke (MyArrayList::convertAll, converter);
|
||||
}
|
||||
|
||||
protected <A, R> R invoke(BiFunction<MyArrayList<E>, A, R> action, A arg) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public class MyArrayList<T> extends ArrayList<T> {
|
||||
public <Output1> List<Output1> convertAll(Function<T, Output1> converter) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -197,6 +197,10 @@ public class NewMethodRefHighlightingTest extends LightDaemonAnalyzerTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testIDEA122100() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
doTest(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user