changeset 57001:6b7ea91a2528 records-and-sealed

fixing more bugs on records, more changes to RecordCompilationTests
author vromero
date Fri, 16 Aug 2019 17:11:04 -0400
parents b58b165af743
children 475bf8c9563b 4750d96927b1
files src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symbol.java src/jdk.compiler/share/classes/com/sun/tools/javac/comp/TypeEnter.java src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties test/langtools/tools/javac/records/RecordCompilationTests.java test/langtools/tools/javac/records/mandated_members/read_resolve_method/CheckReadResolveMethodTest.java
diffstat 5 files changed, 15 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symbol.java	Fri Aug 16 14:31:37 2019 -0400
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symbol.java	Fri Aug 16 17:11:04 2019 -0400
@@ -414,6 +414,10 @@
         return (flags_field & Flags.AccessFlags) == PRIVATE;
     }
 
+    public boolean isPublic() {
+        return (flags_field & Flags.AccessFlags) == PUBLIC;
+    }
+
     public boolean isEnum() {
         return (flags() & ENUM) != 0;
     }
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/TypeEnter.java	Fri Aug 16 14:31:37 2019 -0400
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/TypeEnter.java	Fri Aug 16 17:11:04 2019 -0400
@@ -1231,6 +1231,9 @@
                     if (!initParamNames.equals(recordComponentNames)) {
                         log.error(canonicalDecl, Errors.CanonicalWithNameMismatch);
                     }
+                    if (!canonicalInit.isPublic()) {
+                        log.error(canonicalDecl, Errors.CanonicalConstructorMustBePublic);
+                    }
                     // let's use the RECORD flag to mark it as the canonical constructor
                     canonicalInit.flags_field |= Flags.RECORD;
                 }
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties	Fri Aug 16 14:31:37 2019 -0400
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties	Fri Aug 16 17:11:04 2019 -0400
@@ -3457,6 +3457,9 @@
 compiler.err.method.must.be.public=\
     method: {0}(), must be public
 
+compiler.err.canonical.constructor.must.be.public=\
+    canonical constructor must be public
+
 compiler.err.canonical.with.name.mismatch=\
     constructor with same signature as canonical does not match by parameter names
 
--- a/test/langtools/tools/javac/records/RecordCompilationTests.java	Fri Aug 16 14:31:37 2019 -0400
+++ b/test/langtools/tools/javac/records/RecordCompilationTests.java	Fri Aug 16 17:11:04 2019 -0400
@@ -104,7 +104,7 @@
         assertFail("compiler.err.expected", "record R(foo) { }");
         assertFail("compiler.err.expected", "record R(int int) { }");
         assertFail("compiler.err.restricted.type.not.allowed.here", "record R(var x) { }");
-        // @@@ assertFail("compiler.err.restricted.type.not.allowed.here", "record R(record x) { }");
+        assertFail("compiler.err.restricted.type.not.allowed.here", "record R(record x) { }");
         assertFail("compiler.err.record.cant.declare.field.modifiers", "record R(public String foo) { }");
         assertFail("compiler.err.record.cant.declare.field.modifiers", "record R(private String foo) { }");
         assertFail("compiler.err.mod.not.allowed.here", "abstract record R(String foo) { }");
@@ -168,7 +168,6 @@
     }
 
     public void testNoExtendRecord() {
-        // @@@ Not finished, waiting on j.l.Record
         assertFail("compiler.err.invalid.supertype.record",
                    "class R extends Record { public String toString() { return null; } public int hashCode() { return 0; } public boolean equals(Object o) { return false; } } }");
     }
@@ -247,17 +246,14 @@
 //                   "public R(int x, int y) { this.x = x; }");
 
         // canonical ctor must be public
-        // @@@ Should fail
-//        assertFail("", "record R(int x, int y) { # }",
-//                   "R(int x, int y) { this.x = x; this.y = y; }");
+        assertFail("compiler.err.canonical.constructor.must.be.public", "record R(int x, int y) { # }",
+                   "R(int x, int y) { this.x = x; this.y = y; }");
 
         // ctor args must match types
-        /*
-        assertFail("",
+        assertFail("compiler.err.constructor.with.same.erasure.as.canonical",
                 "import java.util.*;\n" +
                         "record R(List<String> list) { # }",
                 "R(List list) { this.list = list; }");
-        */
     }
 
     public void testAnnotationCriteria() {
--- a/test/langtools/tools/javac/records/mandated_members/read_resolve_method/CheckReadResolveMethodTest.java	Fri Aug 16 14:31:37 2019 -0400
+++ b/test/langtools/tools/javac/records/mandated_members/read_resolve_method/CheckReadResolveMethodTest.java	Fri Aug 16 17:11:04 2019 -0400
@@ -38,7 +38,7 @@
 
     // readResolve should be generated as a constructor is provided
     record Point1(int i, int j) implements Serializable {
-        Point1(int i, int j) {
+        public Point1(int i, int j) {
             this.i = i;
             this.j = j;
         }