From 026dc4c813bd0b26defe54989ea0929e6d9eb511 Mon Sep 17 00:00:00 2001 From: Jan Lahoda Date: Mon, 13 Oct 2025 13:56:09 +0200 Subject: [PATCH] Adding tests with generic records. --- .../tools/javac/patterns/Exhaustiveness.java | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/test/langtools/tools/javac/patterns/Exhaustiveness.java b/test/langtools/tools/javac/patterns/Exhaustiveness.java index 5a252c75695..7c521c32e76 100644 --- a/test/langtools/tools/javac/patterns/Exhaustiveness.java +++ b/test/langtools/tools/javac/patterns/Exhaustiveness.java @@ -2219,6 +2219,40 @@ public class Exhaustiveness extends TestRunner { record Root(Base b1, Base b2, Base b3) {} } """); + doTest(base, + new String[0], + """ + package test; + public class Test { + private int test(Root r) { + return switch (r) { + case Root(R1 _, _, _) -> 0; + case Root(R2 _, R1 _, _) -> 0; + case Root(R2 _, R2 _, R1 _) -> 0; + case Root(R2 _, R2(R1 _, R1 _), R2(R1 _, R1 _)) -> 0; + case Root(R2 _, R2(R1 _, R1 _), R2(R1 _, R2 _)) -> 0; + case Root(R2 _, R2(R1 _, R1 _), R2(R2 _, R1 _)) -> 0; + case Root(R2 _, R2(R1 _, R1 _), R2(R2 _, R2 _)) -> 0; + case Root(R2 _, R2(R1 _, R2 _), R2(R1 _, R1 _)) -> 0; + case Root(R2 _, R2(R1 _, R2 _), R2(R1 _, R2 _)) -> 0; + case Root(R2 _, R2(R1 _, R2 _), R2(R2 _, R1 _)) -> 0; + case Root(R2 _, R2(R1 _, R2 _), R2(R2 _, R2 _)) -> 0; + case Root(R2 _, R2(R2 _, R1 _), R2(R1 _, R1 _)) -> 0; + case Root(R2 _, R2(R2 _, R1 _), R2(R1 _, R2 _)) -> 0; + case Root(R2 _, R2(R2 _, R1 _), R2(R2 _, R1 _)) -> 0; + case Root(R2 _, R2(R2 _, R1 _), R2(R2 _, R2 _)) -> 0; + case Root(R2 _, R2(R2 _, R2 _), R2(R1 _, R1 _)) -> 0; + case Root(R2 _, R2(R2 _, R2 _), R2(R1 _, R2 _)) -> 0; + case Root(R2 _, R2(R2 _, R2 _), R2(R2 _, R1 _)) -> 0; + case Root(R2 _, R2(R2 _, R2 _), R2 _) -> 0; //functionally equivalent to: Root(R2 _, R2(R2 _, R2 _), R2(R2 _, R2 _)) + }; + } + sealed interface Base {} + record R1() implements Base {} + record R2(Base b1, Base b2) implements Base {} + record Root(T b1, T b2, T b3) {} + } + """); } @Test //JDK-8364991 @@ -2250,6 +2284,33 @@ public class Exhaustiveness extends TestRunner { record Root(R2 b2, R2 b3) {} } """); + doTest(base, + new String[0], + """ + package test; + public class Test { + private int test1(Root> r) { + return switch (r) { + case Root(R2(R1 _), R2(R1 _)) -> 0; + case Root(R2(R1 _), R2(R2 _)) -> 0; + case Root(R2(R2 _), R2(R1 _)) -> 0; + case Root(R2(R2 _), R2 _) -> 0; + }; + } + private int test2(Root> r) { + return switch (r) { + case Root(R2(R1 _), R2(R1 _)) -> 0; + case Root(R2(R2 _), R2(R1 _)) -> 0; + case Root(R2(R1 _), R2(R2 _)) -> 0; + case Root(R2 _, R2(R2 _)) -> 0; + }; + } + sealed interface Base {} + record R1() implements Base {} + record R2(T b1) implements Base {} + record Root(T b2, T b3) {} + } + """); } @Test //JDK-8364991 @@ -2274,6 +2335,26 @@ public class Exhaustiveness extends TestRunner { """, "Test.java:4:16: compiler.err.not.exhaustive", "1 error"); + doTest(base, + new String[0], + """ + package test; + public class Test { + private int test(Root> r) { + return switch (r) { + case Root(R2 _, R2(R1 _)) -> 0; + case Root(R2(R1 _), R2(R2 _)) -> 0; + case Root(R2(R2 _), R2 _) -> 0; + }; + } + sealed interface Base {} + record R1() implements Base {} + record R2(T b) implements Base {} + record Root(T b2, T b3) {} + } + """, + "Test.java:4:16: compiler.err.not.exhaustive", + "1 error"); } private void doTest(Path base, String[] libraryCode, String testCode, String... expectedErrors) throws IOException {