mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
lambda: void-compatibility check for expression's lambda void type conditional
(cherry picked from commit 76bab4d85984e95279b0358b53ff85734c4589a5)
This commit is contained in:
@@ -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
@@ -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>;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user