-
Bug
-
Resolution: Fixed
-
P2
-
21
-
b07
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8312927 | 21.0.1 | Jan Lahoda | P2 | Resolved | Fixed | b04 |
JDK-8311039 | 21 | Jan Lahoda | P2 | Resolved | Fixed | b32 |
Consider code like:
---
public class Test {
record Rec(Object t) {}
private void test1() {
Rec r = new Rec("test");
int res = switch (r) {
case Rec(String x): {
yield 4;
}
case Rec(Object x): {
yield -3;
}
};
if (r instanceof Rec(String x)) {
System.out.println(x.length());
}
}
private void test2() {
Rec r = new Rec("test");
int res = switch (r) {
case Rec(String x): {
yield x.length();
}
case Rec(Object x): {
yield -3;
}
};
}
}
---
this leads to:
---
/home/work/src/jdk/jdk/test/langtools/tools/Test.java:14: error: the switch expression does not cover all possible input values
int res = switch (r) {
^
/home/work/src/jdk/jdk/test/langtools/tools/Test.java:30: error: the switch expression does not cover all possible input values
int res = switch (r) {
^
2 errors
---
which is obviously wrong, because the switches are exhaustive.
Also not that code like:
---
public class Test {
record Rec(Object t) {}
private void test0() {
Rec r = new Rec("test");
int res = switch (r) {
case Rec(String x): {
yield 4;
}
case Rec(Object x): {
yield -3;
}
};
}
}
---
despite having the overall structure as the original code. That is a Symbol completion issue that needs to be handled as well.
---
public class Test {
record Rec(Object t) {}
private void test1() {
Rec r = new Rec("test");
int res = switch (r) {
case Rec(String x): {
yield 4;
}
case Rec(Object x): {
yield -3;
}
};
if (r instanceof Rec(String x)) {
System.out.println(x.length());
}
}
private void test2() {
Rec r = new Rec("test");
int res = switch (r) {
case Rec(String x): {
yield x.length();
}
case Rec(Object x): {
yield -3;
}
};
}
}
---
this leads to:
---
/home/work/src/jdk/jdk/test/langtools/tools/Test.java:14: error: the switch expression does not cover all possible input values
int res = switch (r) {
^
/home/work/src/jdk/jdk/test/langtools/tools/Test.java:30: error: the switch expression does not cover all possible input values
int res = switch (r) {
^
2 errors
---
which is obviously wrong, because the switches are exhaustive.
Also not that code like:
---
public class Test {
record Rec(Object t) {}
private void test0() {
Rec r = new Rec("test");
int res = switch (r) {
case Rec(String x): {
yield 4;
}
case Rec(Object x): {
yield -3;
}
};
}
}
---
despite having the overall structure as the original code. That is a Symbol completion issue that needs to be handled as well.
- backported by
-
JDK-8311039 Incorrect exhaustivity computation
- Resolved
-
JDK-8312927 Incorrect exhaustivity computation
- Resolved
- links to
-
Commit openjdk/jdk21/7a5d6f90
-
Commit openjdk/jdk/bbb7ce51
-
Review openjdk/jdk21/127
-
Review openjdk/jdk/14711
(1 links to)