|
1 | 1 | /* |
2 | | - * Copyright (c) 2016, 2022, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2016, 2024, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 | 4 | * |
5 | 5 | * This code is free software; you can redistribute it and/or modify it |
|
23 | 23 |
|
24 | 24 | /** |
25 | 25 | * @test |
26 | | - * @bug 8262891 8268871 8274363 8281100 8294670 8311038 8311815 8325215 8333169 |
| 26 | + * @bug 8262891 8268871 8274363 8281100 8294670 8311038 8311815 8325215 8333169 8327368 |
27 | 27 | * @summary Check exhaustiveness of switches over sealed types. |
28 | 28 | * @library /tools/lib |
29 | 29 | * @modules jdk.compiler/com.sun.tools.javac.api |
@@ -2105,6 +2105,83 @@ static <T> T log(T t) { |
2105 | 2105 | }"""); |
2106 | 2106 | } |
2107 | 2107 |
|
| 2108 | + @Test |
| 2109 | + public void testNestedIntersectionType(Path base) throws Exception { |
| 2110 | + doTest(base, |
| 2111 | + new String[0], |
| 2112 | + """ |
| 2113 | + public class Test { |
| 2114 | +
|
| 2115 | + static abstract class Abs {} |
| 2116 | +
|
| 2117 | + sealed interface B permits V {} |
| 2118 | +
|
| 2119 | + static final class V extends Abs implements B {} |
| 2120 | +
|
| 2121 | + final static record R<T extends B>(T b) {} |
| 2122 | +
|
| 2123 | + static <T extends Abs & B> int r(R<T> r) { |
| 2124 | + return switch (r) { |
| 2125 | + case R(B b) -> 3; |
| 2126 | + }; |
| 2127 | + } |
| 2128 | + } |
| 2129 | + """); |
| 2130 | + } |
| 2131 | + @Test //JDK-8327368 |
| 2132 | + public void testExpandForTypeVariables(Path base) throws Exception { |
| 2133 | + doTest(base, |
| 2134 | + new String[0], |
| 2135 | + """ |
| 2136 | + public class Test { |
| 2137 | + sealed interface A permits T, U {} |
| 2138 | + sealed interface B permits V, W {} |
| 2139 | +
|
| 2140 | + static final class T implements A { public T() {} } |
| 2141 | + static final class U implements A { public U() {} } |
| 2142 | +
|
| 2143 | + static final class V implements B { public V() {} } |
| 2144 | + static final class W implements B { public W() {} } |
| 2145 | +
|
| 2146 | + final static record R<T1 extends A, T2 extends B>(T1 a, T2 b) { } |
| 2147 | +
|
| 2148 | + static <T1 extends A, T2 extends B> int r(R<T1, T2> r) { |
| 2149 | + return switch (r) { |
| 2150 | + case R(A a, V b) -> 1; // Any A with specific B |
| 2151 | + case R(T a, var b) -> 2; // Specific A with any B |
| 2152 | + case R(U a, W b) -> 3; // Specific A with specific B |
| 2153 | + }; |
| 2154 | + } |
| 2155 | + } |
| 2156 | + """); |
| 2157 | + doTest(base, |
| 2158 | + new String[0], |
| 2159 | + """ |
| 2160 | + public class Test { |
| 2161 | + sealed interface A permits T, U {} |
| 2162 | + sealed interface B permits V, W {} |
| 2163 | +
|
| 2164 | + static final class T implements A { public T() {} } |
| 2165 | + static final class U implements A { public U() {} } |
| 2166 | +
|
| 2167 | + static final class V extends Abs implements B { public V() {} } |
| 2168 | + static final class W extends Abs implements B { public W() {} } |
| 2169 | +
|
| 2170 | + static abstract class Abs {} |
| 2171 | +
|
| 2172 | + final static record R<T1 extends A, T2 extends B>(T1 a, T2 b) { } |
| 2173 | +
|
| 2174 | + static <T1 extends A, T2 extends Abs & B> int r(R<T1, T2> r) { |
| 2175 | + return switch (r) { |
| 2176 | + case R(A a, V b) -> 1; // Any A with specific B |
| 2177 | + case R(T a, var b) -> 2; // Specific A with any B |
| 2178 | + case R(U a, W b) -> 3; // Specific A with specific B |
| 2179 | + }; |
| 2180 | + } |
| 2181 | + } |
| 2182 | + """); |
| 2183 | + } |
| 2184 | + |
2108 | 2185 | private void doTest(Path base, String[] libraryCode, String testCode, String... expectedErrors) throws IOException { |
2109 | 2186 | doTest(base, libraryCode, testCode, false, expectedErrors); |
2110 | 2187 | } |
|
0 commit comments