Skip to content

Commit ec93cc5

Browse files
committed
8343932: Error when parsing qualified generic type test pattern in switch
Reviewed-by: jlahoda
1 parent c330b90 commit ec93cc5

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -3428,7 +3428,7 @@ PatternResult analyzePattern(int lookahead) {
34283428
case GTGT: typeDepth--;
34293429
case GT:
34303430
typeDepth--;
3431-
if (typeDepth == 0) {
3431+
if (typeDepth == 0 && !peekToken(lookahead, DOT)) {
34323432
return peekToken(lookahead, LAX_IDENTIFIER) ||
34333433
peekToken(lookahead, tk -> tk == LPAREN) ? PatternResult.PATTERN
34343434
: PatternResult.EXPRESSION;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
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.
8+
*
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).
14+
*
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.
18+
*
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
21+
* questions.
22+
*/
23+
/**
24+
* @test
25+
* @bug 8343932
26+
* @summary Error when parsing qualified generic type test pattern in switch
27+
* @compile T8343932.java
28+
*/
29+
public class T8343932 {
30+
abstract sealed class J<T1, T2> permits X.S, A {}
31+
final class A extends J<Integer, Integer> {}
32+
33+
public class X<T> {
34+
final class S<U> extends J<T, U> {
35+
abstract sealed class J<T1, T2> permits XX.SS, AA {}
36+
final class AA extends J<Integer, Integer> {}
37+
38+
public class XX<T> {
39+
final class SS<U> extends J<T, U> {}
40+
}
41+
}
42+
43+
static int test(J<Integer, Integer> ji) {
44+
return switch (ji) {
45+
case A a -> 42;
46+
case X<Integer>.S<Integer> e -> 4200; // level 1
47+
};
48+
}
49+
50+
static int test(X<Integer>.S<Integer>.J<Integer, Integer> ji) {
51+
return switch (ji) {
52+
case X<Integer>.S<Integer>.AA a -> 42;
53+
case X<Integer>.S<Integer>.XX<Integer>.SS<Integer> e -> 4200; // level 2
54+
};
55+
}
56+
}
57+
}

0 commit comments

Comments
 (0)