changeset 58362:a69ac8d0dc21 records

more diags tests
author vromero
date Sun, 20 Oct 2019 21:03:40 -0400
parents c6eb43a894cc
children b3e8bdfcb968
files src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties test/langtools/tools/javac/diags/examples.not-yet.txt test/langtools/tools/javac/diags/examples/AccessorReturnTypeDoesntMatch.java test/langtools/tools/javac/diags/examples/CanonicalConstructorArgumentMismatch.java test/langtools/tools/javac/diags/examples/CanonicalConstructorCantHaveReturn.java test/langtools/tools/javac/diags/examples/CanonicalConstructorMustBePublic.java test/langtools/tools/javac/diags/examples/ConstructorWithSameErasureAsCanonical.java test/langtools/tools/javac/diags/examples/Expected3.java test/langtools/tools/javac/diags/examples/IllegalRecordComponentName.java test/langtools/tools/javac/diags/examples/IllegalRecordMember.java test/langtools/tools/javac/diags/examples/IllegalStartOfStmt.java test/langtools/tools/javac/diags/examples/InvalidSuperTypeRecord.java test/langtools/tools/javac/diags/examples/MethodCantThrowCheckedException.java test/langtools/tools/javac/diags/examples/MethodMustBePublic.java test/langtools/tools/javac/diags/examples/RecordFieldsMustBeInHeader.java test/langtools/tools/javac/diags/examples/Records.java test/langtools/tools/javac/diags/examples/RecordsCanNotBeAbstract.java test/langtools/tools/javac/diags/examples/RecordsCantDeclareComponentModifiers.java test/langtools/tools/javac/diags/examples/RecordsCantDeclareDuplicateComponents.java
diffstat 22 files changed, 246 insertions(+), 61 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java	Sun Oct 20 15:24:06 2019 -0400
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java	Sun Oct 20 21:03:40 2019 -0400
@@ -1178,9 +1178,6 @@
                     (flags & ENUM) != 0) {
                     log.error(pos, Errors.EnumsMustBeStatic);
                 }
-                if ((flags & RECORD) != 0 && (flags & STATIC) == 0) {
-                    log.error(pos, Errors.NestedRecordsMustBeStatic);
-                }
             } else if (sym.owner.kind == TYP) {
                 mask = (flags & RECORD) != 0 ? MemberRecordClassFlags : MemberClassFlags;
                 if (sym.owner.owner.kind == PCK ||
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java	Sun Oct 20 15:24:06 2019 -0400
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java	Sun Oct 20 21:03:40 2019 -0400
@@ -1191,7 +1191,7 @@
                 }
             },
 
-            new AttributeReader(names.Record, V57, CLASS_ATTRIBUTE) {
+            new AttributeReader(names.Record, V58, CLASS_ATTRIBUTE) {
                 @Override
                 protected boolean accepts(AttributeKind kind) {
                     return super.accepts(kind) && allowRecords;
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java	Sun Oct 20 15:24:06 2019 -0400
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java	Sun Oct 20 21:03:40 2019 -0400
@@ -3792,13 +3792,12 @@
     Name typeName() {
         int pos = token.pos;
         Name name = ident();
+        /* if (isRestrictedRecordTypeName(name)) {
+            reportSyntaxError(pos, Errors.RecordNotAllowed(name));
+        }*/
         if (isRestrictedTypeName(name, pos, true)) {
             reportSyntaxError(pos, Errors.RestrictedTypeNotAllowed(name, name == names.var ? Source.JDK10 : Source.JDK13));
         }
-
-        if (isRestrictedRecordTypeName(name)) {
-            reportSyntaxError(pos, Errors.RecordNotAllowed(name));
-        }
         return name;
     }
 
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties	Sun Oct 20 15:24:06 2019 -0400
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties	Sun Oct 20 21:03:40 2019 -0400
@@ -3414,30 +3414,10 @@
     records cannot be abstract
 
 compiler.err.record.cant.declare.duplicate.fields=\
-    records cannot declare fields with the same name
+    records cannot declare components with the same name
 
 compiler.err.record.cant.declare.field.modifiers=\
-    records cannot declare field modifiers
-
-compiler.err.record.can.only.declare.methods.as.members=\
-    records can only declare methods as members
-
-# 0: fragment
-compiler.err.cant.extend.record=\
-    Illegal ''extends'' clause for record\n\
-    {0}
-
-compiler.misc.bad.record.super=\
-    A record must extend class AbstractRecord or an ''abstract'' record
-
-# 0: type, 1: name, 2: type, 3: name
-compiler.misc.super.field.mismatch=\
-    Superclass field declaration mismatch\n\
-    expected: {0} {1}\n\
-    found: {2} {3}
-
-compiler.misc.bad.super.fields=\
-    A record cannot have both an explicit constructor, and an implicit superclass header.
+    record components can not have modifiers
 
 compiler.err.record.fields.must.be.in.header=\
     instance fields in a record must be declared in the header
@@ -3445,18 +3425,6 @@
 compiler.err.local.record=\
     records must not be local
 
-compiler.err.nested.records.must.be.static=\
-    nested records must always be static
-
-# 0: name
-compiler.err.duplicate.argument.to.super=\
-    duplicate argument {0}, arguments passed to the super of a record must be unique
-
-# 0: name
-compiler.err.record.not.allowed=\
-    ''{0}'' not allowed here\n\
-    as of release 14, ''{0}'' is a restricted type name and cannot be used for type declarations
-
 # 0: name
 compiler.err.method.must.be.public=\
     method: {0}(), must be public
--- a/test/langtools/tools/javac/diags/examples.not-yet.txt	Sun Oct 20 15:24:06 2019 -0400
+++ b/test/langtools/tools/javac/diags/examples.not-yet.txt	Sun Oct 20 21:03:40 2019 -0400
@@ -165,24 +165,7 @@
 compiler.misc.file.does.not.contain.module
 
 # records related messages
-compiler.err.duplicate.argument.to.super
-compiler.err.expected3
-compiler.misc.bad.super.fields
-compiler.misc.super.field.mismatch
-compiler.err.accessor.return.type.doesnt.match
-compiler.err.canonical.with.name.mismatch
-compiler.err.cant.extend.record
-compiler.err.constructor.with.same.erasure.as.canonical
 compiler.err.local.record
-compiler.err.method.must.be.public
-compiler.err.nested.records.must.be.static
-compiler.err.record.can.only.declare.methods.as.members
-compiler.err.record.cant.be.abstract
-compiler.err.record.cant.declare.duplicate.fields
-compiler.err.record.cant.declare.field.modifiers
-compiler.err.record.fields.must.be.in.header
-compiler.err.record.not.allowed
-compiler.misc.bad.record.super
 
 # these keys were in javac.properties and examples are hard to be produced for them
 # basically because in most cases the compilation ends with an exception
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/tools/javac/diags/examples/AccessorReturnTypeDoesntMatch.java	Sun Oct 20 21:03:40 2019 -0400
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2019, 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.
+ */
+
+// key: compiler.err.accessor.return.type.doesnt.match
+// options: --enable-preview -source ${jdk.version}
+
+import java.util.List;
+record R(List<String> x) {
+    public List<Object> x() { return null; };
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/tools/javac/diags/examples/CanonicalConstructorArgumentMismatch.java	Sun Oct 20 21:03:40 2019 -0400
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2019, 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.
+ */
+
+// key: compiler.err.canonical.with.name.mismatch
+// options: --enable-preview -source ${jdk.version}
+
+record R(int x) {
+    public R(int _x) { this.x = _x; }
+}
--- a/test/langtools/tools/javac/diags/examples/CanonicalConstructorCantHaveReturn.java	Sun Oct 20 15:24:06 2019 -0400
+++ b/test/langtools/tools/javac/diags/examples/CanonicalConstructorCantHaveReturn.java	Sun Oct 20 21:03:40 2019 -0400
@@ -22,6 +22,7 @@
  */
 
 // key: compiler.err.canonical.cant.have.return.statement
+// options: --enable-preview -source ${jdk.version}
 
 record R() {
     public R {
--- a/test/langtools/tools/javac/diags/examples/CanonicalConstructorMustBePublic.java	Sun Oct 20 15:24:06 2019 -0400
+++ b/test/langtools/tools/javac/diags/examples/CanonicalConstructorMustBePublic.java	Sun Oct 20 21:03:40 2019 -0400
@@ -22,6 +22,7 @@
  */
 
 // key: compiler.err.canonical.constructor.must.be.public
+// options: --enable-preview -source ${jdk.version}
 
 record R(int i) {
     R(int i) { this.i = i; }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/tools/javac/diags/examples/ConstructorWithSameErasureAsCanonical.java	Sun Oct 20 21:03:40 2019 -0400
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2019, 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.
+ */
+
+// key: compiler.err.constructor.with.same.erasure.as.canonical
+// options: --enable-preview -source ${jdk.version}
+
+import java.util.List;
+
+@SuppressWarnings("unchecked")
+record R(List<String> x) {
+    public R(List x) { this.x = x; }
+}
--- a/test/langtools/tools/javac/diags/examples/Expected3.java	Sun Oct 20 15:24:06 2019 -0400
+++ b/test/langtools/tools/javac/diags/examples/Expected3.java	Sun Oct 20 21:03:40 2019 -0400
@@ -21,6 +21,6 @@
  * questions.
  */
 
-// key: compiler.err.expected4
+// key: compiler.err.expected3
 
 int Expected3;
--- a/test/langtools/tools/javac/diags/examples/IllegalRecordComponentName.java	Sun Oct 20 15:24:06 2019 -0400
+++ b/test/langtools/tools/javac/diags/examples/IllegalRecordComponentName.java	Sun Oct 20 21:03:40 2019 -0400
@@ -22,5 +22,6 @@
  */
 
 // key: compiler.err.illegal.record.component.name
+// options: --enable-preview -source ${jdk.version}
 
 record R(int hashCode) {}
--- a/test/langtools/tools/javac/diags/examples/IllegalRecordMember.java	Sun Oct 20 15:24:06 2019 -0400
+++ b/test/langtools/tools/javac/diags/examples/IllegalRecordMember.java	Sun Oct 20 21:03:40 2019 -0400
@@ -22,6 +22,7 @@
  */
 
 // key: compiler.err.illegal.record.member
+// options: --enable-preview -source ${jdk.version}
 
 record R() {
     private void readObjectNoData() { }
--- a/test/langtools/tools/javac/diags/examples/IllegalStartOfStmt.java	Sun Oct 20 15:24:06 2019 -0400
+++ b/test/langtools/tools/javac/diags/examples/IllegalStartOfStmt.java	Sun Oct 20 21:03:40 2019 -0400
@@ -23,6 +23,7 @@
 
 // key: compiler.err.illegal.start.of.stmt
 // key: compiler.err.expected4
+// options: --enable-preview -source ${jdk.version}
 
 class IllegalStartOfStmt {
     void m() {
--- a/test/langtools/tools/javac/diags/examples/InvalidSuperTypeRecord.java	Sun Oct 20 15:24:06 2019 -0400
+++ b/test/langtools/tools/javac/diags/examples/InvalidSuperTypeRecord.java	Sun Oct 20 21:03:40 2019 -0400
@@ -23,4 +23,5 @@
 
 // key: compiler.err.invalid.supertype.record
 
+@SuppressWarnings("removal")
 class R extends Record {}
--- a/test/langtools/tools/javac/diags/examples/MethodCantThrowCheckedException.java	Sun Oct 20 15:24:06 2019 -0400
+++ b/test/langtools/tools/javac/diags/examples/MethodCantThrowCheckedException.java	Sun Oct 20 21:03:40 2019 -0400
@@ -22,6 +22,7 @@
  */
 
 // key: compiler.err.method.cant.throw.checked.exception
+// options: --enable-preview -source ${jdk.version}
 
 record R(int x) {
     public int x() throws Exception { return 0; }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/tools/javac/diags/examples/MethodMustBePublic.java	Sun Oct 20 21:03:40 2019 -0400
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2019, 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.
+ */
+
+// key: compiler.err.method.must.be.public
+// options: --enable-preview -source ${jdk.version}
+
+record R(int x) {
+    private int x() { return x; }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/tools/javac/diags/examples/RecordFieldsMustBeInHeader.java	Sun Oct 20 21:03:40 2019 -0400
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2019, 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.
+ */
+
+// key: compiler.err.record.fields.must.be.in.header
+// key: compiler.err.illegal.start.of.type
+// options: --enable-preview -source ${jdk.version}
+
+record R(int i) {
+    private final int y = 0;
+}
--- a/test/langtools/tools/javac/diags/examples/Records.java	Sun Oct 20 15:24:06 2019 -0400
+++ b/test/langtools/tools/javac/diags/examples/Records.java	Sun Oct 20 21:03:40 2019 -0400
@@ -23,6 +23,6 @@
 
 // key: compiler.misc.feature.records
 // key: compiler.warn.preview.feature.use.plural
-// options: --enable-preview -source ${jdk.version} -Xlint:preview
+// options: --enable-preview -source ${jdk.version}
 
 record R() {}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/tools/javac/diags/examples/RecordsCanNotBeAbstract.java	Sun Oct 20 21:03:40 2019 -0400
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2019, 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.
+ */
+
+// key: compiler.err.record.cant.be.abstract
+// options: --enable-preview -source ${jdk.version}
+
+abstract record R() {}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/tools/javac/diags/examples/RecordsCantDeclareComponentModifiers.java	Sun Oct 20 21:03:40 2019 -0400
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2019, 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.
+ */
+
+// key: compiler.err.record.cant.declare.field.modifiers
+// options: --enable-preview -source ${jdk.version}
+
+record R(final int x) {}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/tools/javac/diags/examples/RecordsCantDeclareDuplicateComponents.java	Sun Oct 20 21:03:40 2019 -0400
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2019, 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.
+ */
+
+// key: compiler.err.record.cant.declare.duplicate.fields
+// options: --enable-preview -source ${jdk.version}
+
+record R(int x, int x) {}