lambda: correct error reporting according to b.50

This commit is contained in:
Anna Kozlova
2012-08-20 15:26:47 +04:00
parent 05c0cfbb5e
commit 122cccf567
2 changed files with 11 additions and 9 deletions
@@ -104,10 +104,12 @@ public class LambdaUtil {
if (returnType == PsiType.VOID) {
final PsiElement body = lambdaExpression.getBody();
if (body instanceof PsiCodeBlock) {
if (!lambdaExpression.getReturnExpressions().isEmpty()) return "Cannot return a value from method whose result type is void";
if (!lambdaExpression.getReturnExpressions().isEmpty()) return "Unexpected return value";
} else if (body instanceof PsiExpression) {
final PsiType type = ((PsiExpression)body).getType();
return "Incompatible return type " + (type == PsiType.NULL || type == null ? "<null>" : type.getPresentableText()) +" in lambda expression";
if (type != PsiType.VOID) {
return "Incompatible return type " + (type == PsiType.NULL || type == null ? "<null>" : type.getPresentableText()) +" in lambda expression";
}
}
} else if (returnType != null) {
final List<PsiExpression> returnExpressions = lambdaExpression.getReturnExpressions();
@@ -118,7 +120,7 @@ public class LambdaUtil {
}
}
if (returnExpressions.isEmpty()) {
return "Incompatible return type void in lambda expression";
return "Missing return value";
}
}
return null;