[java-dfa] IDEA-349093 Cast to unresolved reference inside try-catch causes 'Unreachable code' warning

GitOrigin-RevId: c9098e741070cddd1c89936045481521d5823bf7
This commit is contained in:
Tagir Valeev
2024-03-13 21:17:47 +00:00
committed by intellij-monorepo-bot
parent e19f123a6c
commit 5e168b68c6
3 changed files with 14 additions and 1 deletions
@@ -79,7 +79,7 @@ public class TypeCastInstruction extends ExpressionPushingInstruction {
List<DfaInstructionState> result = new ArrayList<>();
if (myTransferValue != null) {
DfaMemoryState castFail = stateBefore.createCopy();
if (fromType != null && myCastTo.isConvertibleFrom(fromType)) {
if (fromType != null && (!constraint.isResolved() || myCastTo.isConvertibleFrom(fromType))) {
if (!castTopOfStack(factory, stateBefore, constraint)) {
castPossible = false;
} else {
@@ -0,0 +1,11 @@
class Test {
void test(Object obj) {
try {
System.out.println((<error descr="Cannot resolve symbol 'MyUnresolvedClass'">MyUnresolvedClass</error>)obj);
System.out.println("hello");
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
@@ -41,6 +41,8 @@ public class UnreachableCodeInspectionTest extends LightJavaCodeInsightFixtureTe
public void testLambdaCast() { doTest(); }
public void testFailingCast() { doTest(); }
public void testUnresolvedCast() { doTest(); }
private void doTest() {
myFixture.configureByFile(getTestName(false) + ".java");