mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
lambda expression isCongruent: ensure target function type has no type parameters
This commit is contained in:
+4
-3
@@ -177,9 +177,6 @@ public class PsiLambdaExpressionImpl extends ExpressionPsiElement implements Psi
|
||||
}
|
||||
final PsiExpressionList argsList = PsiTreeUtil.getParentOfType(this, PsiExpressionList.class);
|
||||
|
||||
leftType = FunctionalInterfaceParameterizationUtil.getGroundTargetType(leftType, this);
|
||||
|
||||
final PsiClassType.ClassResolveResult resolveResult = PsiUtil.resolveGenericsClassInType(leftType);
|
||||
if (MethodCandidateInfo.ourOverloadGuard.currentStack().contains(argsList)) {
|
||||
final MethodCandidateInfo.CurrentCandidateProperties candidateProperties = MethodCandidateInfo.getCurrentMethod(argsList);
|
||||
if (candidateProperties != null) {
|
||||
@@ -194,6 +191,7 @@ public class PsiLambdaExpressionImpl extends ExpressionPsiElement implements Psi
|
||||
}
|
||||
}
|
||||
|
||||
leftType = FunctionalInterfaceParameterizationUtil.getGroundTargetType(leftType, this);
|
||||
if (!isPotentiallyCompatible(leftType)) {
|
||||
return false;
|
||||
}
|
||||
@@ -202,9 +200,12 @@ public class PsiLambdaExpressionImpl extends ExpressionPsiElement implements Psi
|
||||
return true;
|
||||
}
|
||||
|
||||
final PsiClassType.ClassResolveResult resolveResult = PsiUtil.resolveGenericsClassInType(leftType);
|
||||
final PsiMethod interfaceMethod = LambdaUtil.getFunctionalInterfaceMethod(resolveResult);
|
||||
if (interfaceMethod == null) return false;
|
||||
|
||||
if (interfaceMethod.hasTypeParameters()) return false;
|
||||
|
||||
final PsiSubstitutor substitutor = LambdaUtil.getSubstitutor(interfaceMethod, resolveResult);
|
||||
|
||||
if (hasFormalParameterTypes()) {
|
||||
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
interface I {
|
||||
void g();
|
||||
|
||||
}
|
||||
interface J {
|
||||
<<warning descr="Type parameter 'T' is never used">T</warning>> void f();
|
||||
}
|
||||
class Test {
|
||||
void m(I i) {System.out.println(i);}
|
||||
void m(J j) {System.out.println(j);}
|
||||
|
||||
void m2(J j){System.out.println(j);}
|
||||
|
||||
{
|
||||
m (() -> {});
|
||||
m2(<error descr="Target method is generic">() -> {}</error>);
|
||||
}
|
||||
}
|
||||
+4
@@ -67,6 +67,10 @@ public class OverloadResolutionTest extends LightDaemonAnalyzerTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testLambdaIsNotCongruentWithFunctionalTypeWithTypeParams() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
doTest(true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user