changeset 59591:0bec7f3c8a7e

8236841: compact constructor parameters are always final Reviewed-by: mcimadamore
author vromero
date Fri, 10 Jan 2020 15:32:04 -0500
parents 737b8cdeb0f1
children 7e0af9d375bf
files src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java test/langtools/tools/javac/records/RecordCompilationTests.java
diffstat 2 files changed, 13 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java	Fri Jan 10 21:09:53 2020 +0100
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java	Fri Jan 10 15:32:04 2020 -0500
@@ -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 @@
                     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();
--- a/test/langtools/tools/javac/records/RecordCompilationTests.java	Fri Jan 10 21:09:53 2020 +0100
+++ b/test/langtools/tools/javac/records/RecordCompilationTests.java	Fri Jan 10 15:32:04 2020 -0500
@@ -429,6 +429,17 @@
         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 {}");