mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
lambda: void compatibility guess
This commit is contained in:
@@ -40,7 +40,7 @@ public class LambdaHighlightingUtil {
|
||||
final PsiElement body = lambdaExpression.getBody();
|
||||
if (body instanceof PsiCodeBlock) {
|
||||
if (!LambdaUtil.getReturnExpressions(lambdaExpression).isEmpty()) return "Unexpected return value";
|
||||
} else if (body instanceof PsiExpression) {
|
||||
} else if (body instanceof PsiReferenceExpression || body instanceof PsiLiteralExpression) {
|
||||
final PsiType type = ((PsiExpression)body).getType();
|
||||
if (type != PsiType.VOID) {
|
||||
return "Incompatible return type " + (type == PsiType.NULL || type == null ? "<null>" : type.getPresentableText()) +" in lambda expression";
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
public class Main {
|
||||
interface I<T> {
|
||||
void m(T t);
|
||||
}
|
||||
|
||||
{
|
||||
String s = "";
|
||||
I<Object> arr1 = <error descr="Incompatible return type String in lambda expression">(t) -> s</error>;
|
||||
I<Object> arr2 = (t) -> s.toString();
|
||||
}
|
||||
|
||||
}
|
||||
+4
@@ -220,6 +220,10 @@ public class LambdaHighlightingTest extends LightDaemonAnalyzerTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testVoidCompatibility() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTest() throws Exception {
|
||||
doTest(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user