mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-05-06 05:10:22 +07:00
functional type erasure: check if resulted type functional (IDEA-142341)
This commit is contained in:
@@ -78,14 +78,14 @@ public class PsiTypeVisitor<A> {
|
||||
public A visitLambdaExpressionType(PsiLambdaExpressionType lambdaExpressionType) {
|
||||
final PsiLambdaExpression lambdaExpression = lambdaExpressionType.getExpression();
|
||||
final PsiType interfaceType = lambdaExpression.getFunctionalInterfaceType();
|
||||
if (interfaceType != null) return interfaceType.accept(this);
|
||||
if (interfaceType != null && LambdaUtil.isFunctionalType(interfaceType)) return interfaceType.accept(this);
|
||||
return visitType(lambdaExpressionType);
|
||||
}
|
||||
|
||||
public A visitMethodReferenceType(PsiMethodReferenceType methodReferenceType) {
|
||||
final PsiMethodReferenceExpression expression = methodReferenceType.getExpression();
|
||||
final PsiType interfaceType = expression.getFunctionalInterfaceType();
|
||||
if (interfaceType != null) return interfaceType.accept(this);
|
||||
if (interfaceType != null && LambdaUtil.isFunctionalType(interfaceType)) return interfaceType.accept(this);
|
||||
return visitType(methodReferenceType);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
interface Functional {
|
||||
void a(String s);
|
||||
}
|
||||
|
||||
interface NonFunctional {
|
||||
void b(String s);
|
||||
void c();
|
||||
}
|
||||
|
||||
interface P<<warning descr="Type parameter 'T' is never used">T</warning>> {
|
||||
void subscribe(Functional f);
|
||||
void subscribe(NonFunctional nf);
|
||||
}
|
||||
|
||||
class Test {
|
||||
void foo(P p) {
|
||||
p.subscribe(s -> {});
|
||||
}
|
||||
}
|
||||
|
||||
interface FunctionalExact {
|
||||
void a();
|
||||
}
|
||||
|
||||
interface NonFunctionalExact {
|
||||
void b();
|
||||
void c();
|
||||
}
|
||||
|
||||
interface PExact<<warning descr="Type parameter 'T' is never used">T</warning>> {
|
||||
void subscribe(FunctionalExact f);
|
||||
void subscribe(NonFunctionalExact nf);
|
||||
}
|
||||
|
||||
class TestExact {
|
||||
void foo(PExact p) {
|
||||
p.subscribe(() -> {});
|
||||
}
|
||||
}
|
||||
@@ -130,6 +130,10 @@ public class OverloadResolutionTest extends LightDaemonAnalyzerTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testFunctionalExpressionTypeErasure() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
doTest(true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user