changeset 57905:c78c8c9fcda5 records-and-sealed

dont allow native methods in records
author vromero
date Thu, 10 Oct 2019 13:52:06 -0400
parents 4e5c9c683088
children 543585aa050d
files src/jdk.compiler/share/classes/com/sun/tools/javac/code/Flags.java src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java test/langtools/tools/javac/records/RecordCompilationTests.java
diffstat 3 files changed, 15 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Flags.java	Thu Oct 10 13:31:31 2019 -0400
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Flags.java	Thu Oct 10 13:52:06 2019 -0400
@@ -366,7 +366,9 @@
         ConstructorFlags                 = AccessFlags,
         InterfaceMethodFlags             = ABSTRACT | PUBLIC,
         MethodFlags                      = AccessFlags | ABSTRACT | STATIC | NATIVE |
-                                           SYNCHRONIZED | FINAL | STRICTFP;
+                                           SYNCHRONIZED | FINAL | STRICTFP,
+        RecordMethodFlags                = AccessFlags | ABSTRACT | STATIC |
+                                            SYNCHRONIZED | FINAL | STRICTFP;
     public static final long
         ExtendedStandardFlags            = (long)StandardFlags | DEFAULT | SEALED | NON_SEALED,
         ExtendedLocalClassFlags          = (long)LocalClassFlags | SEALED | NON_SEALED,
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java	Thu Oct 10 13:31:31 2019 -0400
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java	Thu Oct 10 13:52:06 2019 -0400
@@ -1168,6 +1168,8 @@
                 } else {
                     mask = implicit = InterfaceMethodFlags;
                 }
+            } else if ((sym.owner.flags_field & RECORD) != 0) {
+                mask = RecordMethodFlags;
             } else {
                 mask = MethodFlags;
             }
--- a/test/langtools/tools/javac/records/RecordCompilationTests.java	Thu Oct 10 13:31:31 2019 -0400
+++ b/test/langtools/tools/javac/records/RecordCompilationTests.java	Thu Oct 10 13:52:06 2019 -0400
@@ -383,5 +383,15 @@
     public void testReturnInCanonical() {
         assertFail("compiler.err.canonical.cant.have.return.statement", "record R(int x) { # }",
                 "public R { return; }");
+        assertFail("compiler.err.canonical.cant.have.return.statement", "record R(int x) { # }",
+                "public R { if (i < 0) { return; }}");
+        assertOK("record R(int x) { public R { Runnable r = () -> {return;};} }");
+    }
+
+    public void testNoNativeMethods() {
+        assertFail("compiler.err.mod.not.allowed.here", "record R(int x) { # }",
+                "public native R {}");
+        assertFail("compiler.err.mod.not.allowed.here", "record R(int x) { # }",
+                "public native void m();");
     }
 }