mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-240631 "Switch label is unreachable" false positive with OptionalInt
GitOrigin-RevId: 0ba6182fe01fc0909883fc098497c91b1a585a57
This commit is contained in:
committed by
intellij-monorepo-bot
parent
7a67795522
commit
6515b045d9
+6
-1
@@ -120,7 +120,12 @@ public class DfaExpressionFactory {
|
||||
}
|
||||
|
||||
DfaValue qualifier = getQualifierOrThisValue(refExpr);
|
||||
return var.createValue(myFactory, qualifier, true);
|
||||
DfaValue result = var.createValue(myFactory, qualifier, true);
|
||||
if (var instanceof SpecialField) {
|
||||
PsiType wantedType = refExpr.getType();
|
||||
result = DfaUtil.boxUnbox(result, wantedType);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
import java.util.OptionalInt;
|
||||
import java.util.Random;
|
||||
|
||||
class OptionalIntSwitch {
|
||||
// IDEA-240631
|
||||
public static void main(String[] args) {
|
||||
OptionalInt opt = OptionalInt.of(new Random().nextInt() % 2);
|
||||
|
||||
switch (opt.getAsInt()) {
|
||||
case 0:
|
||||
System.out.println("zero");
|
||||
break;
|
||||
case 1:
|
||||
System.out.println("one");
|
||||
break;
|
||||
case <warning descr="Switch label '2' is unreachable">2</warning>:
|
||||
System.out.println("two");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -42,6 +42,7 @@ public class DataFlowInspection8Test extends DataFlowInspectionTestCase {
|
||||
public void testOptionalOfNullable() { doTest(); }
|
||||
public void testPrimitiveOptional() { doTest(); }
|
||||
public void testOptionalOrElse() { doTest(); }
|
||||
public void testOptionalIntSwitch() { doTest(); }
|
||||
public void testOptionalIsPresent() {
|
||||
myFixture.addClass("package org.junit;" +
|
||||
"public class Assert {" +
|
||||
|
||||
Reference in New Issue
Block a user