diff --git a/java/java-psi-api/src/com/intellij/psi/LambdaUtil.java b/java/java-psi-api/src/com/intellij/psi/LambdaUtil.java index 848327da0cfe..683dd21f80fb 100644 --- a/java/java-psi-api/src/com/intellij/psi/LambdaUtil.java +++ b/java/java-psi-api/src/com/intellij/psi/LambdaUtil.java @@ -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 ? "" : type.getPresentableText()) +" in lambda expression"; + if (type != PsiType.VOID) { + return "Incompatible return type " + (type == PsiType.NULL || type == null ? "" : type.getPresentableText()) +" in lambda expression"; + } } } else if (returnType != null) { final List 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; diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/highlighting/IncompatibleReturnTypes.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/highlighting/IncompatibleReturnTypes.java index d7ada0d3d851..61b13e5c0e04 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/highlighting/IncompatibleReturnTypes.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/highlighting/IncompatibleReturnTypes.java @@ -4,9 +4,9 @@ class Test1 { void foo(); } { - VoidReturnType aI = () -> System.out.println(); + VoidReturnType aI = () -> System.out.println(); VoidReturnType aI1 = () -> {System.out.println();}; - VoidReturnType aI2 = () -> {return 1;}; + VoidReturnType aI2 = () -> {return 1;}; VoidReturnType aI3 = () -> 1; VoidReturnType aI4 = () -> {return;}; } @@ -18,7 +18,7 @@ class Test2 { } { IntReturnType aI = () -> System.out.println(); - IntReturnType aI1 = () -> {System.out.println();}; + IntReturnType aI1 = () -> {System.out.println();}; IntReturnType aI2 = () -> {return 1;}; IntReturnType aI3 = () -> 1; } @@ -32,10 +32,10 @@ class Test3 { } { XReturnType aI = () -> System.out.println(); - XReturnType aI1 = () -> {System.out.println();}; + XReturnType aI1 = () -> {System.out.println();}; XReturnType aI2 = () -> {return 1;}; XReturnType aI3 = () -> 1; - XReturnType aI4 = () -> {}; + XReturnType aI4 = () -> {}; } } @@ -48,7 +48,7 @@ class Test4 { { YXReturnType aI = () -> System.out.println(); - YXReturnType aI1 = () -> {System.out.println();}; + YXReturnType aI1 = () -> {System.out.println();}; YXReturnType aI2 = () -> {return 1;}; YXReturnType aI3 = () -> 1; YXReturnType aI4 = () -> new Y(){};