From 1c17012fa57b7b6f0238018c803d87e2938ed103 Mon Sep 17 00:00:00 2001 From: Jan Lahoda Date: Tue, 27 Jan 2026 17:24:34 +0100 Subject: [PATCH] Fixing tests. --- .../javac/diags/examples/BindingPattern.java | 33 +++++++++++++++++++ ...eDetails.java => EnumConstantPattern.java} | 11 ++++--- .../javac/diags/examples/NotExhaustive.java | 2 +- .../examples/NotExhaustiveStatement.java | 2 +- ...atementDetails.java => RecordPattern.java} | 18 ++++++---- .../PrimitiveInstanceOfComboTest.java | 6 ++-- .../PrimitivePatternsSwitchConstants.java | 2 +- .../PrimitivePatternsSwitchErrors.java | 2 +- .../tools/javac/patterns/SwitchErrors.java | 2 +- .../platform/NonExportedPermittedTypes.java | 6 ++-- .../ExpressionSwitchNotExhaustive.java | 2 +- 11 files changed, 63 insertions(+), 23 deletions(-) create mode 100644 test/langtools/tools/javac/diags/examples/BindingPattern.java rename test/langtools/tools/javac/diags/examples/{NotExhaustiveDetails.java => EnumConstantPattern.java} (84%) rename test/langtools/tools/javac/diags/examples/{NotExhaustiveStatementDetails.java => RecordPattern.java} (75%) diff --git a/test/langtools/tools/javac/diags/examples/BindingPattern.java b/test/langtools/tools/javac/diags/examples/BindingPattern.java new file mode 100644 index 00000000000..01913a47fd7 --- /dev/null +++ b/test/langtools/tools/javac/diags/examples/BindingPattern.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +// key: compiler.err.not.exhaustive.details +// key: compiler.misc.binding.pattern + +class BindingPattern { + int t(Object o) { + return switch (o) { + case String s -> 0; + }; + } +} diff --git a/test/langtools/tools/javac/diags/examples/NotExhaustiveDetails.java b/test/langtools/tools/javac/diags/examples/EnumConstantPattern.java similarity index 84% rename from test/langtools/tools/javac/diags/examples/NotExhaustiveDetails.java rename to test/langtools/tools/javac/diags/examples/EnumConstantPattern.java index 1a7e82b12e7..49d3de7aeed 100644 --- a/test/langtools/tools/javac/diags/examples/NotExhaustiveDetails.java +++ b/test/langtools/tools/javac/diags/examples/EnumConstantPattern.java @@ -22,13 +22,16 @@ */ // key: compiler.err.not.exhaustive.details -// key: compiler.misc.not.exhaustive.detail -// options: -XDexhaustivityTimeout=-1 +// key: compiler.misc.enum.constant.pattern class NotExhaustiveDetails { - int t(int i) { + int t(I i) { return switch (i) { - case 0 -> -1; + case R r -> -1; + case E.A -> -1; }; } + sealed interface I {} + enum E implements I {A, B} + record R(E e) implements I {} } diff --git a/test/langtools/tools/javac/diags/examples/NotExhaustive.java b/test/langtools/tools/javac/diags/examples/NotExhaustive.java index b5ba932ac60..efaf95c6472 100644 --- a/test/langtools/tools/javac/diags/examples/NotExhaustive.java +++ b/test/langtools/tools/javac/diags/examples/NotExhaustive.java @@ -22,7 +22,7 @@ */ // key: compiler.err.not.exhaustive -// options: -XDexhaustivityTimeout=0 +// options: -XDexhaustivityMaxBaseChecks=0 class NotExhaustive { int t(int i) { diff --git a/test/langtools/tools/javac/diags/examples/NotExhaustiveStatement.java b/test/langtools/tools/javac/diags/examples/NotExhaustiveStatement.java index 9a3da048d7c..dfda499505f 100644 --- a/test/langtools/tools/javac/diags/examples/NotExhaustiveStatement.java +++ b/test/langtools/tools/javac/diags/examples/NotExhaustiveStatement.java @@ -22,7 +22,7 @@ */ // key: compiler.err.not.exhaustive.statement -// options: -XDexhaustivityTimeout=0 +// options: -XDexhaustivityMaxBaseChecks=0 class NotExhaustive { void t(Object o) { diff --git a/test/langtools/tools/javac/diags/examples/NotExhaustiveStatementDetails.java b/test/langtools/tools/javac/diags/examples/RecordPattern.java similarity index 75% rename from test/langtools/tools/javac/diags/examples/NotExhaustiveStatementDetails.java rename to test/langtools/tools/javac/diags/examples/RecordPattern.java index 650a81a01af..5d066de46d2 100644 --- a/test/langtools/tools/javac/diags/examples/NotExhaustiveStatementDetails.java +++ b/test/langtools/tools/javac/diags/examples/RecordPattern.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -22,13 +22,17 @@ */ // key: compiler.err.not.exhaustive.statement.details -// key: compiler.misc.not.exhaustive.detail -// options: -XDexhaustivityTimeout=-1 +// key: compiler.misc.record.pattern +// key: compiler.misc.binding.pattern -class NotExhaustiveDetails { - void t(Object o) { - switch (o) { - case String s -> System.err.println("String of length: " + s.length()); +class RecordPattern { + void t(R r) { + switch (r) { + case R(C1 _) -> {} }; } + sealed interface I {} + record C1() implements I {} + record C2() implements I {} + record R(I i) {} } diff --git a/test/langtools/tools/javac/patterns/PrimitiveInstanceOfComboTest.java b/test/langtools/tools/javac/patterns/PrimitiveInstanceOfComboTest.java index a0fe66f1f2c..ca686994e10 100644 --- a/test/langtools/tools/javac/patterns/PrimitiveInstanceOfComboTest.java +++ b/test/langtools/tools/javac/patterns/PrimitiveInstanceOfComboTest.java @@ -103,19 +103,19 @@ public class PrimitiveInstanceOfComboTest extends ComboInstance { diff --git a/test/langtools/tools/javac/patterns/PrimitivePatternsSwitchConstants.java b/test/langtools/tools/javac/patterns/PrimitivePatternsSwitchConstants.java index 1c5131e730c..249cdeb2464 100644 --- a/test/langtools/tools/javac/patterns/PrimitivePatternsSwitchConstants.java +++ b/test/langtools/tools/javac/patterns/PrimitivePatternsSwitchConstants.java @@ -2,7 +2,7 @@ * @test /nodynamiccopyright/ * @summary Retain exhaustiveness properties of switches with a constant selector * @enablePreview - * @compile/fail/ref=PrimitivePatternsSwitchConstants.out -XDrawDiagnostics -XDshould-stop.at=FLOW -XDexhaustivityTimeout=0 PrimitivePatternsSwitchConstants.java + * @compile/fail/ref=PrimitivePatternsSwitchConstants.out -XDrawDiagnostics -XDshould-stop.at=FLOW -XDexhaustivityMaxBaseChecks=0 PrimitivePatternsSwitchConstants.java */ public class PrimitivePatternsSwitchConstants { void testConstExpressions() { diff --git a/test/langtools/tools/javac/patterns/PrimitivePatternsSwitchErrors.java b/test/langtools/tools/javac/patterns/PrimitivePatternsSwitchErrors.java index 4427dac9fcd..3eab2fc83d0 100644 --- a/test/langtools/tools/javac/patterns/PrimitivePatternsSwitchErrors.java +++ b/test/langtools/tools/javac/patterns/PrimitivePatternsSwitchErrors.java @@ -3,7 +3,7 @@ * @bug 8304487 8325653 8332463 * @summary Compiler Implementation for Primitive types in patterns, instanceof, and switch (Preview) * @enablePreview - * @compile/fail/ref=PrimitivePatternsSwitchErrors.out -XDrawDiagnostics -XDshould-stop.at=FLOW -XDexhaustivityTimeout=0 PrimitivePatternsSwitchErrors.java + * @compile/fail/ref=PrimitivePatternsSwitchErrors.out -XDrawDiagnostics -XDshould-stop.at=FLOW -XDexhaustivityMaxBaseChecks=0 PrimitivePatternsSwitchErrors.java */ public class PrimitivePatternsSwitchErrors { record R_int(int x) {} diff --git a/test/langtools/tools/javac/patterns/SwitchErrors.java b/test/langtools/tools/javac/patterns/SwitchErrors.java index 0594ab1d825..ebff13e7fa5 100644 --- a/test/langtools/tools/javac/patterns/SwitchErrors.java +++ b/test/langtools/tools/javac/patterns/SwitchErrors.java @@ -2,7 +2,7 @@ * @test /nodynamiccopyright/ * @bug 8262891 8269146 8269113 8348928 * @summary Verify errors related to pattern switches. - * @compile/fail/ref=SwitchErrors.out -XDrawDiagnostics -XDshould-stop.at=FLOW -XDexhaustivityTimeout=0 SwitchErrors.java + * @compile/fail/ref=SwitchErrors.out -XDrawDiagnostics -XDshould-stop.at=FLOW -XDexhaustivityMaxBaseChecks=0 SwitchErrors.java */ public class SwitchErrors { diff --git a/test/langtools/tools/javac/platform/NonExportedPermittedTypes.java b/test/langtools/tools/javac/platform/NonExportedPermittedTypes.java index 0343490359b..8a325283d88 100644 --- a/test/langtools/tools/javac/platform/NonExportedPermittedTypes.java +++ b/test/langtools/tools/javac/platform/NonExportedPermittedTypes.java @@ -26,9 +26,9 @@ * @bug 8318913 * @summary Verify no error is when compiling a class whose permitted types are not exported * @modules jdk.compiler - * @compile/fail/ref=NonExportedPermittedTypes.out -XDrawDiagnostics -XDexhaustivityTimeout=0 NonExportedPermittedTypes.java - * @compile/fail/ref=NonExportedPermittedTypes.out --release 21 -XDrawDiagnostics -XDexhaustivityTimeout=0 NonExportedPermittedTypes.java - * @compile/fail/ref=NonExportedPermittedTypes.out --release ${jdk.version} -XDrawDiagnostics -XDexhaustivityTimeout=0 NonExportedPermittedTypes.java + * @compile/fail/ref=NonExportedPermittedTypes.out -XDrawDiagnostics -XDexhaustivityMaxBaseChecks=0 NonExportedPermittedTypes.java + * @compile/fail/ref=NonExportedPermittedTypes.out --release 21 -XDrawDiagnostics -XDexhaustivityMaxBaseChecks=0 NonExportedPermittedTypes.java + * @compile/fail/ref=NonExportedPermittedTypes.out --release ${jdk.version} -XDrawDiagnostics -XDexhaustivityMaxBaseChecks=0 NonExportedPermittedTypes.java */ diff --git a/test/langtools/tools/javac/switchexpr/ExpressionSwitchNotExhaustive.java b/test/langtools/tools/javac/switchexpr/ExpressionSwitchNotExhaustive.java index a301f715a90..05a73c0ba7a 100644 --- a/test/langtools/tools/javac/switchexpr/ExpressionSwitchNotExhaustive.java +++ b/test/langtools/tools/javac/switchexpr/ExpressionSwitchNotExhaustive.java @@ -2,7 +2,7 @@ * @test /nodynamiccopyright/ * @bug 8206986 * @summary Verify behavior of not exhaustive switch expressions. - * @compile/fail/ref=ExpressionSwitchNotExhaustive.out -XDrawDiagnostics -XDexhaustivityTimeout=0 ExpressionSwitchNotExhaustive.java + * @compile/fail/ref=ExpressionSwitchNotExhaustive.out -XDrawDiagnostics -XDexhaustivityMaxBaseChecks=0 ExpressionSwitchNotExhaustive.java */ public class ExpressionSwitchNotExhaustive {