diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/ExpressionCompatibilityConstraint.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/ExpressionCompatibilityConstraint.java index 0f8edeeab4e8..1bf06dfd52ad 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/ExpressionCompatibilityConstraint.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/constraints/ExpressionCompatibilityConstraint.java @@ -30,6 +30,9 @@ public class ExpressionCompatibilityConstraint extends InputOutputConstraintForm if (!PsiPolyExpressionUtil.isPolyExpression(myExpression)) { PsiType exprType = myExpression.getType(); + if (exprType != null) { + exprType = exprType.annotate(TypeAnnotationProvider.EMPTY); + } if (session.isProperType(myT)) { final boolean assignmentCompatible = exprType == null || TypeConversionUtil.isAssignable(myT, exprType); diff --git a/java/java-tests/testData/inspection/dataFlow/fixture/TypeUseLambdaReturn.java b/java/java-tests/testData/inspection/dataFlow/fixture/TypeUseLambdaReturn.java new file mode 100644 index 000000000000..34b94980e47e --- /dev/null +++ b/java/java-tests/testData/inspection/dataFlow/fixture/TypeUseLambdaReturn.java @@ -0,0 +1,25 @@ +import ambiguous.*; + +class Test { + void run1() { + String result = compute(() -> { + return Math.random() > 0.5 ? getResult() : getResult2(); + }); + if (result == null) {} + } + + void run() { + String result = compute(() -> { + return Math.random() > 0.5 ? getResult() : null; + }); + if (result == null) {} + } + + native @NotNull String getResult(); + native @Nullable String getResult2(); + public native static T compute(Computable action); +} + +interface Computable { + T compute(); +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/java/codeInspection/DataFlowInspection8Test.java b/java/java-tests/testSrc/com/intellij/java/codeInspection/DataFlowInspection8Test.java index cd8fe2486457..f588d08c47ba 100644 --- a/java/java-tests/testSrc/com/intellij/java/codeInspection/DataFlowInspection8Test.java +++ b/java/java-tests/testSrc/com/intellij/java/codeInspection/DataFlowInspection8Test.java @@ -155,6 +155,10 @@ public class DataFlowInspection8Test extends DataFlowInspectionTestCase { public void testCapturedWildcardNotNull() { doTest(); } public void testVarargNotNull() { doTestWithCustomAnnotations(); } public void testIgnoreNullabilityOnPrimitiveCast() { doTestWithCustomAnnotations();} + public void testTypeUseLambdaReturn() { + setupTypeUseAnnotations("ambiguous", myFixture); + doTest(); + } public void testArrayComponentAndMethodAnnotationConflict() { setupAmbiguousAnnotations("withTypeUse", myFixture);