8311038: Incorrect exhaustivity computation
Reviewed-by: vromero
This commit is contained in:
parent
2e12a123c9
commit
bbb7ce5137
@ -844,6 +844,8 @@ public class Flow {
|
|||||||
for (Type sup : types.directSupertypes(bpOne.type)) {
|
for (Type sup : types.directSupertypes(bpOne.type)) {
|
||||||
ClassSymbol clazz = (ClassSymbol) sup.tsym;
|
ClassSymbol clazz = (ClassSymbol) sup.tsym;
|
||||||
|
|
||||||
|
clazz.complete();
|
||||||
|
|
||||||
if (clazz.isSealed() && clazz.isAbstract() &&
|
if (clazz.isSealed() && clazz.isAbstract() &&
|
||||||
//if a binding pattern for clazz already exists, no need to analyze it again:
|
//if a binding pattern for clazz already exists, no need to analyze it again:
|
||||||
!existingBindings.contains(clazz)) {
|
!existingBindings.contains(clazz)) {
|
||||||
@ -891,7 +893,9 @@ public class Flow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (reduces) {
|
if (reduces) {
|
||||||
bindings.append(pdOther);
|
if (!types.isSubtype(types.erasure(clazz.type), types.erasure(bpOther.type))) {
|
||||||
|
bindings.append(pdOther);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -926,6 +930,8 @@ public class Flow {
|
|||||||
|
|
||||||
permittedSubtypesClosure = permittedSubtypesClosure.tail;
|
permittedSubtypesClosure = permittedSubtypesClosure.tail;
|
||||||
|
|
||||||
|
current.complete();
|
||||||
|
|
||||||
if (current.isSealed() && current.isAbstract()) {
|
if (current.isSealed() && current.isAbstract()) {
|
||||||
for (Symbol sym : current.permitted) {
|
for (Symbol sym : current.permitted) {
|
||||||
ClassSymbol csym = (ClassSymbol) sym;
|
ClassSymbol csym = (ClassSymbol) sym;
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @bug 8262891 8268871 8274363 8281100 8294670
|
* @bug 8262891 8268871 8274363 8281100 8294670 8311038
|
||||||
* @summary Check exhaustiveness of switches over sealed types.
|
* @summary Check exhaustiveness of switches over sealed types.
|
||||||
* @library /tools/lib
|
* @library /tools/lib
|
||||||
* @modules jdk.compiler/com.sun.tools.javac.api
|
* @modules jdk.compiler/com.sun.tools.javac.api
|
||||||
@ -1948,6 +1948,26 @@ public class Exhaustiveness extends TestRunner {
|
|||||||
""");
|
""");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test //JDK-8311038
|
||||||
|
public void testReducesTooMuch(Path base) throws Exception {
|
||||||
|
doTest(base,
|
||||||
|
new String[0],
|
||||||
|
"""
|
||||||
|
package test;
|
||||||
|
public class Test {
|
||||||
|
void test(Rec r) {
|
||||||
|
switch (r) {
|
||||||
|
case Rec(String s) ->
|
||||||
|
System.out.println("I2" + s.toString());
|
||||||
|
case Rec(Object o) ->
|
||||||
|
System.out.println("I2");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
record Rec(Object o) {}
|
||||||
|
}
|
||||||
|
""");
|
||||||
|
}
|
||||||
|
|
||||||
private void doTest(Path base, String[] libraryCode, String testCode, String... expectedErrors) throws IOException {
|
private void doTest(Path base, String[] libraryCode, String testCode, String... expectedErrors) throws IOException {
|
||||||
doTest(base, libraryCode, testCode, false, expectedErrors);
|
doTest(base, libraryCode, testCode, false, expectedErrors);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user