redundant cast: ensure cast type compared with ground type (IDEA-174369)

remove attempts to emulate that and reuse getGroundTargetType api
This commit is contained in:
Anna Kozlova
2017-06-13 20:27:13 +03:00
parent 7f56e82578
commit 605dfb1c3c
3 changed files with 20 additions and 3 deletions
@@ -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);
}
}
@@ -0,0 +1,18 @@
import java.util.HashMap;
import java.util.Map;
interface A8<A1, A2> {
A2 a(A1 a1);
}
interface B<B1, B2> {
B2 b(B1 b1);
}
class Bug {
<T1, T2> void bug(B<T1, T2> b) {
Map<String, A8<?, T2>> m = new HashMap<>();
// replace with lambda here
m.put("", (A8<T1, T2>) t1 -> b.b(t1));
}
}
@@ -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();
}