8317300: javac erroneously allows "final" in front of a record pattern
Reviewed-by: jlahoda
This commit is contained in:
parent
2bf1863e24
commit
5ca1beb30e
src/jdk.compiler/share/classes/com/sun/tools/javac/parser
test/langtools/tools/javac/patterns
@ -909,6 +909,7 @@ public class JavacParser implements Parser {
|
||||
if (mods.annotations.nonEmpty()) {
|
||||
log.error(mods.annotations.head.pos(), Errors.RecordPatternsAnnotationsNotAllowed);
|
||||
}
|
||||
checkNoMods(pos, mods.flags & Flags.FINAL);
|
||||
new TreeScanner() {
|
||||
@Override
|
||||
public void visitAnnotatedType(JCAnnotatedType tree) {
|
||||
|
24
test/langtools/tools/javac/patterns/T8317300.java
Normal file
24
test/langtools/tools/javac/patterns/T8317300.java
Normal file
@ -0,0 +1,24 @@
|
||||
/*
|
||||
* @test /nodynamiccopyright/
|
||||
* @bug 8317300
|
||||
* @summary javac erroneously allows "final" in front of a record pattern
|
||||
* @compile/fail/ref=T8317300.out -XDrawDiagnostics T8317300.java
|
||||
*/
|
||||
public class T8317300 {
|
||||
record Foo (int x) {}
|
||||
record Bar (Foo x) {}
|
||||
|
||||
void test1(Object obj) {
|
||||
switch (obj) {
|
||||
case final Foo(int x) -> {}
|
||||
default -> {}
|
||||
}
|
||||
}
|
||||
|
||||
void test2(Object obj) {
|
||||
switch (obj) {
|
||||
case Bar(final Foo(int x)) -> {}
|
||||
default -> {}
|
||||
}
|
||||
}
|
||||
}
|
5
test/langtools/tools/javac/patterns/T8317300.out
Normal file
5
test/langtools/tools/javac/patterns/T8317300.out
Normal file
@ -0,0 +1,5 @@
|
||||
T8317300.java:13:18: compiler.err.mod.not.allowed.here: final
|
||||
T8317300.java:20:22: compiler.err.illegal.start.of.expr
|
||||
T8317300.java:20:31: compiler.err.expected: token.identifier
|
||||
T8317300.java:20:37: compiler.err.expected: ';'
|
||||
4 errors
|
Loading…
x
Reference in New Issue
Block a user