8236841: compact constructor parameters are always final

Reviewed-by: mcimadamore
This commit is contained in:
Vicente Romero 2020-01-10 15:32:04 -05:00
parent 2c7c8023ed
commit 4692bc58eb
2 changed files with 13 additions and 2 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2020, 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
@ -3746,7 +3746,7 @@ public class JavacParser implements Parser {
ListBuffer<JCVariableDecl> tmpParams = new ListBuffer<>();
for (JCVariableDecl param : headerFields) {
tmpParams.add(F.at(param)
.VarDef(F.Modifiers(Flags.PARAMETER | param.mods.flags & Flags.VARARGS | param.mods.flags & Flags.FINAL),
.VarDef(F.Modifiers(Flags.PARAMETER | param.mods.flags & Flags.VARARGS),
param.name, param.vartype, null));
}
methDef.params = tmpParams.toList();

View File

@ -429,6 +429,17 @@ public class RecordCompilationTests extends CompilationTestCase {
assertOK("record R(int x) { public R { Runnable r = () -> { return; };} }");
}
public void testArgumentsAreNotFinalInCompact() {
assertOK(
"""
record R(int x) {
public R {
x++;
}
}
""");
}
public void testNoNativeMethods() {
assertFail("compiler.err.mod.not.allowed.here", "record R(int x) { # }",
"public native R {}");