new inference: method reference constraint for the case of return type depends on type params (IDEA-122100)

This commit is contained in:
Anna Kozlova
2014-03-13 17:45:45 +01:00
parent 15eb603d74
commit 766bdc0151
3 changed files with 31 additions and 1 deletions

View File

@@ -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;
}
}

View File

@@ -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;
}
}
}

View File

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