java: redundant cast: don't check casts against non-denotable types

GitOrigin-RevId: ba1ac48a92057ae13f2694a6667e576ca1328134
This commit is contained in:
Anna Kozlova
2020-05-20 06:38:50 +00:00
committed by intellij-monorepo-bot
parent a0cf47d539
commit 0314adac6d
3 changed files with 14 additions and 1 deletions
@@ -624,7 +624,7 @@ public class RedundantCastUtil {
Encoder encoder = new Encoder();
PsiElement encoded = null;
try {
if (typeByParent != null) {
if (typeByParent != null && PsiTypesUtil.isDenotableType(typeByParent, expression)) {
encoder.encode(encoded = expression);
return (PsiCall)LambdaUtil.copyWithExpectedType(expression, typeByParent);
}
@@ -0,0 +1,12 @@
class MyTest {
void m(String[] refInfos){
refInfos = <error descr="Cannot resolve method 'unresolved' in 'MyTest'">unresolved</error>(refInfos, refInfo -> {
refInfo = refInfo.<error descr="Cannot resolve method 'replaceAll(java.lang.String, java.lang.String)'">replaceAll</error>("a", "b");
refInfo = n<error descr="'n(java.lang.String)' in 'MyTest' cannot be applied to '(<lambda parameter>)'">(refInfo)</error>;
return refInfo;
});
}
private static String n(String refInfo) {
return refInfo;
}
}
@@ -99,6 +99,7 @@ public class LambdaRedundantCastTest extends LightDaemonAnalyzerTestCase {
public void testSuperBoundLambda() { doTest(); }
public void testLambdaReturnChain() { doTest(); }
public void testExpectedTypeProducesBadReturnType() { doTest(); }
public void testNonDenotableParent() { doTest(); }
private void doTest() {
doTest(BASE_PATH + "/" + getTestName(false) + ".java", true, false);