8311038: Incorrect exhaustivity computation

Reviewed-by: vromero
This commit is contained in:
Jan Lahoda 2023-07-14 08:21:48 +00:00
parent 2e12a123c9
commit bbb7ce5137
2 changed files with 28 additions and 2 deletions

View File

@ -844,6 +844,8 @@ public class Flow {
for (Type sup : types.directSupertypes(bpOne.type)) {
ClassSymbol clazz = (ClassSymbol) sup.tsym;
clazz.complete();
if (clazz.isSealed() && clazz.isAbstract() &&
//if a binding pattern for clazz already exists, no need to analyze it again:
!existingBindings.contains(clazz)) {
@ -891,7 +893,9 @@ public class Flow {
}
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;
current.complete();
if (current.isSealed() && current.isAbstract()) {
for (Symbol sym : current.permitted) {
ClassSymbol csym = (ClassSymbol) sym;

View File

@ -23,7 +23,7 @@
/**
* @test
* @bug 8262891 8268871 8274363 8281100 8294670
* @bug 8262891 8268871 8274363 8281100 8294670 8311038
* @summary Check exhaustiveness of switches over sealed types.
* @library /tools/lib
* @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 {
doTest(base, libraryCode, testCode, false, expectedErrors);
}