lambda: void compatibility guess

This commit is contained in:
anna
2013-02-20 21:30:51 +01:00
parent 91ab546cf7
commit 6edc546e65
3 changed files with 17 additions and 1 deletions
@@ -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";
@@ -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();
}
}
@@ -220,6 +220,10 @@ public class LambdaHighlightingTest extends LightDaemonAnalyzerTestCase {
doTest();
}
public void testVoidCompatibility() throws Exception {
doTest();
}
private void doTest() throws Exception {
doTest(false);
}