mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 15:24:43 +02:00
8326204: yield statements doesn't allow cast expressions with more than 1 type arguments
Reviewed-by: jlahoda
This commit is contained in:
parent
6f2676dc5f
commit
cff0747d7f
4 changed files with 78 additions and 1 deletions
|
@ -2894,12 +2894,15 @@ public class JavacParser implements Parser {
|
||||||
int lookahead = 2;
|
int lookahead = 2;
|
||||||
int balance = 1;
|
int balance = 1;
|
||||||
boolean hasComma = false;
|
boolean hasComma = false;
|
||||||
|
boolean inTypeArgs = false;
|
||||||
Token l;
|
Token l;
|
||||||
while ((l = S.token(lookahead)).kind != EOF && balance != 0) {
|
while ((l = S.token(lookahead)).kind != EOF && balance != 0) {
|
||||||
switch (l.kind) {
|
switch (l.kind) {
|
||||||
case LPAREN: balance++; break;
|
case LPAREN: balance++; break;
|
||||||
case RPAREN: balance--; break;
|
case RPAREN: balance--; break;
|
||||||
case COMMA: if (balance == 1) hasComma = true; break;
|
case COMMA: if (balance == 1 && !inTypeArgs) hasComma = true; break;
|
||||||
|
case LT: inTypeArgs = true; break;
|
||||||
|
case GT: inTypeArgs = false;
|
||||||
}
|
}
|
||||||
lookahead++;
|
lookahead++;
|
||||||
}
|
}
|
||||||
|
|
59
test/langtools/tools/javac/T8326204a.java
Normal file
59
test/langtools/tools/javac/T8326204a.java
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2024, 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @test
|
||||||
|
* @bug 8326204
|
||||||
|
* @summary yield statements doesn't allow cast expressions with more than 1 type arguments
|
||||||
|
* @compile T8326204a.java
|
||||||
|
*/
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class T8326204a {
|
||||||
|
void testOneParam() {
|
||||||
|
Object value = new ArrayList<String>();
|
||||||
|
Object returnedValue = switch (1) {
|
||||||
|
default -> {
|
||||||
|
yield (List<String>) value;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
void testTwoParams() {
|
||||||
|
Object value = new HashMap<String, String>();
|
||||||
|
Object returnedValue = switch (1) {
|
||||||
|
default -> {
|
||||||
|
yield (Map<String, String>) value;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
void testTwoParamsInParens() {
|
||||||
|
Object value = new HashMap<String, String>();
|
||||||
|
Object returnedValue = switch (1) {
|
||||||
|
default -> {
|
||||||
|
yield ((Map<String, String>) value);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
13
test/langtools/tools/javac/T8326204b.java
Normal file
13
test/langtools/tools/javac/T8326204b.java
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @test /nodynamiccopyright/
|
||||||
|
* @bug 8326204
|
||||||
|
* @summary yield statements doesn't allow cast expressions with more than 1 type arguments
|
||||||
|
* @compile/fail/ref=T8326204b.out -XDrawDiagnostics --should-stop=at=FLOW -XDdev T8326204b.java
|
||||||
|
*/
|
||||||
|
public class T8326204b {
|
||||||
|
private static void t(int i) { yield((Map<String, String>) null, 2); }
|
||||||
|
|
||||||
|
private static void yield(Map<String, String> m, int j) { }
|
||||||
|
}
|
2
test/langtools/tools/javac/T8326204b.out
Normal file
2
test/langtools/tools/javac/T8326204b.out
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
T8326204b.java:10:36: compiler.err.invalid.yield
|
||||||
|
1 error
|
Loading…
Add table
Add a link
Reference in a new issue