mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[java-dfa] IDEA-363270 Misleading warning for switch case when expression on Boolean values
GitOrigin-RevId: 449fdf6cb9137b7dcd038adca7b26ffc15f7d59a
This commit is contained in:
committed by
intellij-monorepo-bot
parent
6a6e2c2eca
commit
68e240546f
+1
@@ -1065,6 +1065,7 @@ public class ControlFlowAnalyzer extends JavaElementVisitor {
|
||||
addInstruction(new GotoInstruction(endGuardOffset));
|
||||
((DeferredOffset)targetOffset).setOffset(getInstructionCount());
|
||||
guard.accept(this);
|
||||
generateBoxingUnboxingInstructionFor(guard, PsiTypes.booleanType());
|
||||
addInstruction(new ResultOfInstruction(new JavaSwitchLabelTakenAnchor(guard)));
|
||||
addInstruction(new ConditionalGotoInstruction(offset, DfTypes.TRUE));
|
||||
endGuardOffset.setOffset(getInstructionCount());
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
// IDEA-363270
|
||||
public class SwitchBooleanWhen {
|
||||
private String testBooleanValue(Object value) {
|
||||
return switch (value) {
|
||||
case Boolean booleanValue when booleanValue -> "true";
|
||||
case Boolean booleanValue when <warning descr="Condition '!booleanValue' is always 'true'">!booleanValue</warning> -> "false";
|
||||
case null -> "null";
|
||||
default -> "unknown";
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -135,6 +135,8 @@ public class DataFlowInspection21Test extends DataFlowInspectionTestCase {
|
||||
public void testInstanceOfPatternAffectNullity() { doTest(); }
|
||||
|
||||
public void testNullabilityInEnumSwitch() { doTest(); }
|
||||
|
||||
public void testSwitchBooleanWhen() { doTest(); }
|
||||
|
||||
public void testJetBrainsNotNullByDefault() {
|
||||
addJetBrainsNotNullByDefault(myFixture);
|
||||
|
||||
Reference in New Issue
Block a user