mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
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:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
+18
@@ -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));
|
||||
}
|
||||
}
|
||||
+1
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user