mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-13 21:55:01 +07:00
redundant cast: do not raise if result in bad return type in lambda expression (IDEA-138927)
This commit is contained in:
@@ -425,10 +425,14 @@ public class RedundantCastUtil {
|
||||
PsiTypeCastExpression castExpression = computeCastExpression.fun(newReturnExpression);
|
||||
PsiExpression castOperand = castExpression.getOperand();
|
||||
if (castOperand == null) return;
|
||||
castExpression.replace(castOperand);
|
||||
castOperand = (PsiExpression)castExpression.replace(castOperand);
|
||||
final PsiType functionalInterfaceType = lambdaExpression.getFunctionalInterfaceType();
|
||||
if (interfaceType.equals(functionalInterfaceType)) {
|
||||
addToResults(returnExpression);
|
||||
final PsiType interfaceReturnType = LambdaUtil.getFunctionalInterfaceReturnType(interfaceType);
|
||||
final PsiType castExprType = castOperand.getType();
|
||||
if (interfaceReturnType != null && castExprType != null && interfaceReturnType.isAssignableFrom(castExprType)) {
|
||||
addToResults(returnExpression);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
import java.util.stream.Stream;
|
||||
|
||||
class Test {
|
||||
public void filterByBoolean(Stream<Object[]> stream) {
|
||||
stream.filter(it -> (Boolean) it[0]);
|
||||
}
|
||||
}
|
||||
+2
@@ -38,6 +38,8 @@ public class LambdaRedundantCastTest extends LightDaemonAnalyzerTestCase {
|
||||
public void testSer() { doTest(); }
|
||||
public void testLambdaReturnExpressions() { doTest(); }
|
||||
public void testLambdaReturnExpressions1() { doTest(); }
|
||||
public void testPreventBadReturnTypeInReturnExpression() { doTest(); }
|
||||
|
||||
private void doTest() {
|
||||
doTest(BASE_PATH + "/" + getTestName(false) + ".java", true, false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user