mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-05 01:50:56 +07:00
most specific check: accept lambdas when target type is type parameter (IDEA-124725)
This commit is contained in:
@@ -153,6 +153,10 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{
|
||||
if (methodParameters.length == 0) continue;
|
||||
final PsiParameter param = i < methodParameters.length ? methodParameters[i] : methodParameters[methodParameters.length - 1];
|
||||
final PsiType paramType = param.getType();
|
||||
// http://docs.oracle.com/javase/specs/jls/se8/html/jls-15.html#jls-15.12.2.1
|
||||
// A lambda expression or a method reference expression is potentially compatible with a type variable if the type variable is a type parameter of the candidate method.
|
||||
final PsiClass paramClass = PsiUtil.resolveClassInType(paramType);
|
||||
if (paramClass instanceof PsiTypeParameter && ((PsiTypeParameter)paramClass).getOwner() == method) continue;
|
||||
if (!lambdaExpression.isAcceptable(((MethodCandidateInfo)conflict).getSubstitutor(false).substitute(paramType), lambdaExpression.hasFormalParameterTypes())) {
|
||||
iterator.remove();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
import java.util.function.Supplier;
|
||||
|
||||
class Test {
|
||||
|
||||
public static void main(String... args) {
|
||||
c<error descr="Cannot resolve method 'c(<lambda expression>, <lambda expression>)'">(() -> 3, () -> 10)</error>;
|
||||
}
|
||||
|
||||
public static <T> void c(Supplier<T> s1, Supplier<T> s2) {}
|
||||
public static <T> void c(Supplier<T> s1, T value) {}
|
||||
}
|
||||
@@ -99,6 +99,10 @@ public class MostSpecificResolutionTest extends LightDaemonAnalyzerTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testTargetTypeParameter() throws Exception {
|
||||
doTest(false);
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
doTest(true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user