diff --git a/java/java-psi-api/src/com/intellij/psi/util/RedundantCastUtil.java b/java/java-psi-api/src/com/intellij/psi/util/RedundantCastUtil.java index 33e0dda0a071..e5faabb02e03 100644 --- a/java/java-psi-api/src/com/intellij/psi/util/RedundantCastUtil.java +++ b/java/java-psi-api/src/com/intellij/psi/util/RedundantCastUtil.java @@ -370,8 +370,9 @@ public class RedundantCastUtil { } } else { final JavaResolveResult newResult = newCall.resolveMethodGenerics(); - if (oldMethod.equals(newResult.getElement()) && newResult.isValidResult() && - Comparing.equal(((PsiCallExpression)newCall).getType(), ((PsiCallExpression)expression).getType())) { + if (oldMethod.equals(newResult.getElement()) && + Comparing.equal(((PsiCallExpression)newCall).getType(), ((PsiCallExpression)expression).getType()) && + newResult.isValidResult()) { final PsiMethod newFunctionalInterfaceMethod = LambdaUtil.getFunctionalInterfaceMethod(newArgs[i]); if (oldFunctionalInterfaceMethod == null || newFunctionalInterfaceMethod != null && (newFunctionalInterfaceMethod == oldFunctionalInterfaceMethod || diff --git a/java/java-tests/testData/inspection/redundantCast/lambda/InferApplicabilityError/expected.xml b/java/java-tests/testData/inspection/redundantCast/lambda/InferApplicabilityError/expected.xml new file mode 100644 index 000000000000..4704d91e891d --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/lambda/InferApplicabilityError/expected.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/java/java-tests/testData/inspection/redundantCast/lambda/InferApplicabilityError/src/Test.java b/java/java-tests/testData/inspection/redundantCast/lambda/InferApplicabilityError/src/Test.java new file mode 100644 index 000000000000..58fd35bfd47f --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/lambda/InferApplicabilityError/src/Test.java @@ -0,0 +1,16 @@ +class RedundantCast { + ParentStrategy strategy; + + public void cast() { + use((ChildStrategy) strategy); + } + + private void use(ChildStrategy strategy) { + } +} + +interface ParentStrategy { +} + +interface ChildStrategy extends ParentStrategy { +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/RedundantCast18Test.java b/java/java-tests/testSrc/com/intellij/codeInspection/RedundantCast18Test.java index d3b13ec6ca54..fe187a68940d 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/RedundantCast18Test.java +++ b/java/java-tests/testSrc/com/intellij/codeInspection/RedundantCast18Test.java @@ -34,6 +34,7 @@ public class RedundantCast18Test extends InspectionTestCase { public void testExpectedSupertype() throws Exception { doTest(); } public void testForeachValue() throws Exception { doTest(); } public void testConditional() throws Exception { doTest(); } + public void testInferApplicabilityError() throws Exception { doTest(); } @Override protected Sdk getTestProjectSdk() {