mirror of
https://github.com/openjdk/jdk.git
synced 2026-05-10 05:29:48 +00:00
8374629: Type test pattern with array type in switch fails to parse
Reviewed-by: vromero
This commit is contained in:
parent
4d316a85a0
commit
fa874fac23
@ -3434,9 +3434,17 @@ public class JavacParser implements Parser {
|
||||
case GT:
|
||||
typeDepth--;
|
||||
if (typeDepth == 0 && !peekToken(lookahead, DOT)) {
|
||||
return peekToken(lookahead, LAX_IDENTIFIER) ||
|
||||
peekToken(lookahead, tk -> tk == LPAREN) ? PatternResult.PATTERN
|
||||
: PatternResult.EXPRESSION;
|
||||
if (peekToken(lookahead, LAX_IDENTIFIER) ||
|
||||
peekToken(lookahead, tk -> tk == LPAREN)) {
|
||||
return PatternResult.PATTERN;
|
||||
}
|
||||
else if (peekToken(lookahead, LBRACKET) ||
|
||||
peekToken(lookahead, MONKEYS_AT)) {
|
||||
break;
|
||||
}
|
||||
else {
|
||||
return PatternResult.EXPRESSION;
|
||||
}
|
||||
} else if (typeDepth < 0) return PatternResult.EXPRESSION;
|
||||
break;
|
||||
case MONKEYS_AT:
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2021, 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
|
||||
@ -113,6 +113,26 @@ public class DisambiguatePatterns {
|
||||
ExpressionType.PATTERN);
|
||||
test.disambiguationTest("R(int x) when (x > 0)",
|
||||
ExpressionType.PATTERN);
|
||||
test.disambiguationTest("java.util.List<?>[] p",
|
||||
ExpressionType.PATTERN);
|
||||
test.disambiguationTest("java.util.List<?>[][] p",
|
||||
ExpressionType.PATTERN);
|
||||
test.disambiguationTest("a<b<c>>[] d",
|
||||
ExpressionType.PATTERN);
|
||||
test.disambiguationTest("java.util.List<?>[] p when true",
|
||||
ExpressionType.PATTERN);
|
||||
test.disambiguationTest("java.util.List<?> @Ann [] p",
|
||||
ExpressionType.PATTERN);
|
||||
test.disambiguationTest("a<b<c>> @Ann [] d",
|
||||
ExpressionType.PATTERN);
|
||||
test.disambiguationTest("(java.util.List<?>[]) o",
|
||||
ExpressionType.EXPRESSION);
|
||||
test.disambiguationTest("String[].class",
|
||||
ExpressionType.EXPRESSION);
|
||||
test.disambiguationTest("new int[1][]",
|
||||
ExpressionType.EXPRESSION);
|
||||
test.disambiguationTest("new java.util.List<?>[1][]",
|
||||
ExpressionType.EXPRESSION);
|
||||
}
|
||||
|
||||
private final ParserFactory factory;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user