2
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
27
* @summary WrongMethodTypeException with pattern matching on switch on sealed classes
29
* @modules jdk.compiler/com.sun.tools.javac.api
30
* jdk.compiler/com.sun.tools.javac.main
31
* jdk.jdeps/com.sun.tools.javap
32
* @build toolbox.ToolBox toolbox.JavapTask
33
* @compile T8328747.java
39
import java.nio.file.Files;
40
import java.nio.file.Path;
41
import java.nio.file.Paths;
43
public class T8328747 extends TestRunner {
46
public static void main(String... args) throws Exception {
47
new T8328747().runTests();
55
public void runTests() throws Exception {
56
runTests(m -> new Object[] { Paths.get(m.getName()) });
60
public void test(Path base) throws Exception {
61
Path current = base.resolve(".");
62
Path src = current.resolve("src");
63
Path classes = current.resolve("classes");
64
tb.writeJavaFiles(src,
68
public static void main(String[] args) {
73
private static void f(I info) {
75
case P p -> System.err.println(p);
76
case O o -> System.err.println(o);
80
static sealed interface I permits P, O {}
81
private abstract static class A {}
82
static final class P extends A implements I {}
83
static final class O extends A implements I {}
87
Files.createDirectories(classes);
91
.options("--release", "21")
93
.files(tb.findJavaFiles(src))
94
.run(Task.Expect.SUCCESS)
97
String javapOut = new JavapTask(tb)
99
.classpath(classes.toString())
100
.classes("test.Test")
102
.getOutput(Task.OutputKind.DIRECT);
104
if (!javapOut.contains("#25 = InvokeDynamic #0:#26 // #0:typeSwitch:(Ljava/lang/Object;I)I"))
105
throw new AssertionError("typeSwitch for a version less than 23 should accept a static type of java.lang.Object");
111
.files(tb.findJavaFiles(src))
112
.run(Task.Expect.SUCCESS)
115
String javapOut = new JavapTask(tb)
117
.classpath(classes.toString())
118
.classes("test.Test")
120
.getOutput(Task.OutputKind.DIRECT);
122
if (!javapOut.contains("#25 = InvokeDynamic #0:#26 // #0:typeSwitch:(Ltest/Test$I;I)I"))
123
throw new AssertionError("typeSwitch from version 23 and beyond should accept a precise selector type");