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 07c5d749a859..5214e3eb0cfa 100644 --- a/java/java-psi-api/src/com/intellij/psi/LambdaUtil.java +++ b/java/java-psi-api/src/com/intellij/psi/LambdaUtil.java @@ -113,8 +113,18 @@ public class LambdaUtil { while (parent instanceof PsiParenthesizedExpression) { parent = parent.getParent(); } - if (parent instanceof PsiExpressionList && functionalInterfaceType instanceof PsiClassType && ((PsiClassType)functionalInterfaceType).isRaw()){ - return false; + if (parent instanceof PsiExpressionList) { + final PsiElement gParent = parent.getParent(); + if (gParent instanceof PsiMethodCallExpression) { + final PsiExpression qualifierExpression = ((PsiMethodCallExpression)gParent).getMethodExpression().getQualifierExpression(); + final PsiType type = qualifierExpression != null ? qualifierExpression.getType() : null; + if (type instanceof PsiClassType && ((PsiClassType)type).isRaw()) { + return true; + } + } + if (functionalInterfaceType instanceof PsiClassType && ((PsiClassType)functionalInterfaceType).isRaw()){ + return false; + } } return true; } @@ -607,12 +617,18 @@ public class LambdaUtil { } private static int isMoreSpecific(PsiType returnType, PsiType returnType1) { - if (returnType instanceof PsiPrimitiveType && returnType != PsiType.VOID && !(returnType1 instanceof PsiPrimitiveType)) { - return -1; + if (returnType == PsiType.VOID || returnType1 == PsiType.VOID) return 0; + if (returnType instanceof PsiPrimitiveType) { + if (!(returnType1 instanceof PsiPrimitiveType)) { + return -1; + } else { + return TypeConversionUtil.areTypesConvertible(returnType, returnType1) ? 1 : -1; + } } - if (returnType1 instanceof PsiPrimitiveType && returnType1 != PsiType.VOID && !(returnType instanceof PsiPrimitiveType)) { + if (returnType1 instanceof PsiPrimitiveType) { return 1; } + final PsiClassType.ClassResolveResult r = PsiUtil.resolveGenericsClassInType(returnType); final PsiClass rClass = r.getElement(); final PsiClassType.ClassResolveResult r1 = PsiUtil.resolveGenericsClassInType(returnType1); diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/highlighting/AmbiguityReturnValueResolution.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/highlighting/AmbiguityReturnValueResolution.java new file mode 100644 index 000000000000..43c4ba966b7b --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/highlighting/AmbiguityReturnValueResolution.java @@ -0,0 +1,26 @@ +public interface IDEA99969 { + default IntStream distinct(Stream s) { + return s.map(i -> (int) i); + } +} +interface Stream { + Stream map(Function mapper); + IntStream map(IntFunction mapper); + LongStream map(LongFunction mapper); +} + +interface Function { + public R apply(T t); +} + +interface IntFunction { + public int applyAsInt(T t); +} + +interface LongFunction { + public long applyAsLong(T t); +} + + +interface IntStream {} +interface LongStream {} diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/LambdaHighlightingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/LambdaHighlightingTest.java index aa42c0b41db0..a88f0c8f1dc2 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/LambdaHighlightingTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/LambdaHighlightingTest.java @@ -204,6 +204,10 @@ public class LambdaHighlightingTest extends LightDaemonAnalyzerTestCase { doTest(); } + public void testAmbiguityReturnValueResolution() throws Exception { + doTest(); + } + private void doTest() throws Exception { doTest(false); }