lambda: void-compatibility check for expression's lambda void type conditional

(cherry picked from commit 76bab4d85984e95279b0358b53ff85734c4589a5)
This commit is contained in:
anna
2013-11-25 16:48:01 +01:00
parent a1bf37f805
commit 709b6166be
2 changed files with 8 additions and 6 deletions
@@ -54,13 +54,12 @@ public class LambdaHighlightingUtil {
if (!LambdaUtil.getReturnExpressions(lambdaExpression).isEmpty()) return "Unexpected return value";
} else if (body instanceof PsiExpression) {
final PsiType type = ((PsiExpression)body).getType();
if (type != PsiType.VOID) {
try {
if (!PsiUtil.isStatement(JavaPsiFacade.getElementFactory(body.getProject()).createStatementFromText(body.getText(), body))) {
return "Incompatible return type " + (type == PsiType.NULL || type == null ? "<null>" : type.getPresentableText()) + " in lambda expression";
}
try {
if (!PsiUtil.isStatement(JavaPsiFacade.getElementFactory(body.getProject()).createStatementFromText(body.getText(), body))) {
return "Incompatible return type " + (type == PsiType.NULL || type == null ? "<null>" : type.getPresentableText()) + " in lambda expression";
}
catch (IncorrectOperationException ignore) {}
}
catch (IncorrectOperationException ignore) {
}
}
} else if (functionalInterfaceReturnType != null) {
@@ -3,6 +3,8 @@ public class Main {
void m(T t);
}
static void foo() {}
{
String s = "";
I<Object> arr1 = <error descr="Incompatible return type String in lambda expression">(t) -> s</error>;
@@ -10,6 +12,7 @@ public class Main {
I<Integer> i1 = <error descr="Incompatible return type int in lambda expression">i -> i * 2</error>;
I<Integer> i2 = <error descr="Incompatible return type int in lambda expression">i -> 2 * i</error>;
I<Integer> i3 = <error descr="Incompatible return type void in lambda expression">i -> true ? foo() : foo()</error>;
}
}