false positive in redundant cast: applicable method with inference error (IDEA-186224)

This commit is contained in:
Anna.Kozlova
2018-02-07 09:44:28 +01:00
parent fb4af6202b
commit be6d0a2981
3 changed files with 17 additions and 1 deletions
@@ -402,7 +402,8 @@ public class RedundantCastUtil {
(!(newCall instanceof PsiCallExpression) ||
oldAnonymousClass != null && newAnonymousClass != null && Comparing.equal(oldAnonymousClass.getBaseClassType(), newAnonymousClass.getBaseClassType()) ||
Comparing.equal(PsiUtil.recaptureWildcards(((PsiCallExpression)newCall).getType(), expression), ((PsiCallExpression)expression).getType())) &&
newResult.isValidResult()) {
newResult.isValidResult() &&
!(newResult instanceof MethodCandidateInfo && ((MethodCandidateInfo)newResult).getInferenceErrorMessage() != null)) {
if (!(newArgs[i] instanceof PsiFunctionalExpression)) {
addToResults(cast);
}
@@ -0,0 +1,14 @@
import java.util.function.Function;
class Test {
static class Node { }
static class ValueNode extends Node {}
static void m(ValueNode v, Node n) {
pathToCustomNode((Node)v, current -> n);
}
public static <T> void pathToCustomNode(T node, Function<T, T> getParent) { }
}
@@ -82,6 +82,7 @@ public class LambdaRedundantCastTest extends LightDaemonAnalyzerTestCase {
public void testCastInConditionalBranch() { doTest();}
public void testCastInsideLambdaReturnExpressionPassedToEnumConstant() { doTest(); }
public void testGroundTargetTypeDiffersFromCastType() { doTest(); }
public void testInferenceErrorForApplicableMethod() { doTest(); }
public void testRejectReturnTypeChange() {
doTest();
}