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 3c3ed346ff3b..b33b95fc1f45 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 @@ -425,9 +425,7 @@ public class RedundantCastUtil { final PsiType parameterType = PsiTypesUtil.getParameterType(parameters, i, varargs); final PsiType newArgType = newResult.getSubstitutor().substitute(parameterType); - //todo replace with castType.equals(FunctionalInterfaceParameterizationUtil.getGroundType(newArgType, lambda)) - if (Comparing.equal(oldResult.getSubstitutor().substitute(parameterType), newArgType) && - Comparing.equal(TypeConversionUtil.erasure(castType), TypeConversionUtil.erasure(newArgType))) { + if (Comparing.equal(castType, ((PsiFunctionalExpression)newArgs[i]).getGroundTargetType(newArgType))) { addToResults(cast); } } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/redundantCast/GroundTargetTypeDiffersFromCastType.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/redundantCast/GroundTargetTypeDiffersFromCastType.java new file mode 100644 index 000000000000..42cf50b0b01d --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/redundantCast/GroundTargetTypeDiffersFromCastType.java @@ -0,0 +1,18 @@ +import java.util.HashMap; +import java.util.Map; + +interface A8 { + A2 a(A1 a1); +} + +interface B { + B2 b(B1 b1); +} + +class Bug { + void bug(B b) { + Map> m = new HashMap<>(); + // replace with lambda here + m.put("", (A8) t1 -> b.b(t1)); + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/java/codeInsight/daemon/lambda/LambdaRedundantCastTest.java b/java/java-tests/testSrc/com/intellij/java/codeInsight/daemon/lambda/LambdaRedundantCastTest.java index d2780d06786c..103d4d53ca20 100644 --- a/java/java-tests/testSrc/com/intellij/java/codeInsight/daemon/lambda/LambdaRedundantCastTest.java +++ b/java/java-tests/testSrc/com/intellij/java/codeInsight/daemon/lambda/LambdaRedundantCastTest.java @@ -80,6 +80,7 @@ public class LambdaRedundantCastTest extends LightDaemonAnalyzerTestCase { public void testInvalidResolveWithoutCast() { doTest();} public void testCastInConditionalBranch() { doTest();} public void testCastInsideLambdaReturnExpressionPassedToEnumConstant() { doTest(); } + public void testGroundTargetTypeDiffersFromCastType() { doTest(); } public void testRejectReturnTypeChange() throws Exception { doTest(); }