Files
Tagir Valeev 9e1742e86a [java-inspections] Do not suggest a fix which breaks the compilation (removing used pattern var)
Fixes IDEA-360403 Quick-fix for always-true pattern breaks the code

GitOrigin-RevId: eb71b14424e628c6b9ea9ca115bc904447e9e7f6
2024-10-17 14:08:04 +00:00

19 lines
541 B
Java

// "Simplify 'u instanceof Upper(Lower l)' to true (may change semantics)" "false"
class X {
void test() {
record Lower(int a, int b) {
}
record Upper(Lower lower) {
}
Object rec = new Upper(new Lower(0, 0));
switch (rec) {
case Upper u when u instanceof <caret>Upper(Lower l) && l instanceof Lower(int a, int b) -> {
System.out.println(u);
System.out.println(l);
System.out.println(a);
}
default -> throw new IllegalStateException("Unexpected value: " + rec);
}
}
}