method refs/lambda: types assignability (IDEA-92786)

This commit is contained in:
anna
2012-10-11 18:13:53 +02:00
parent 56036f1542
commit fedfbcaa85
2 changed files with 31 additions and 0 deletions

View File

@@ -656,6 +656,14 @@ public class TypeConversionUtil {
final PsiMethodReferenceExpression methodReferenceExpression = ((PsiMethodReferenceType)right).getExpression();
if (left instanceof PsiClassType) {
return LambdaUtil.isAcceptable(methodReferenceExpression, (PsiClassType)left);
} else if (left instanceof PsiLambdaExpressionType) {
final PsiType rType = methodReferenceExpression.getFunctionalInterfaceType();
final PsiType lType = ((PsiLambdaExpressionType)left).getExpression().getFunctionalInterfaceType();
return Comparing.equal(rType, lType);
} else if (left instanceof PsiMethodReferenceType) {
final PsiType rType = methodReferenceExpression.getFunctionalInterfaceType();
final PsiType lType = ((PsiMethodReferenceType)left).getExpression().getFunctionalInterfaceType();
return Comparing.equal(rType, lType);
}
}
if (right instanceof PsiLambdaExpressionType) {

View File

@@ -0,0 +1,23 @@
class Test {
void foo(boolean flag) {
Runnable r = null;
Runnable x1 = flag ? System.out::println : System.out::println;
Runnable x2 = flag ? r : System.out::println;
Runnable x3 = flag ? System.out::println : r;
Runnable x4 = flag ? System.out::println : new Runnable() {
@Override
public void run() {
}
};
Runnable x5 = flag ? System.out::println : () -> {
};
Runnable x6 = flag ? () -> {} : System.out::println;
Runnable x7 = flag ? () -> {} : () -> {};
Runnable x8 = flag ? new Runnable() {
@Override
public void run() {
}
} : () -> {};
Runnable x9 = flag ? () -> {} : r;
}
}