changeset 52509:40c0fcc7956a datum

records cant be abstract
author vromero
date Thu, 13 Sep 2018 16:47:16 -0700
parents 010fc837d132
children 55af1bb34978
files 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/datum/DatumShouldDeclareAtLeastOneFieldTest.java test/langtools/tools/javac/datum/DatumShouldDeclareAtLeastOneFieldTest.out test/langtools/tools/javac/datum/Neg01.java test/langtools/tools/javac/datum/RecordsCantBeAbstractTest.java test/langtools/tools/javac/datum/RecordsCantBeAbstractTest.out
diffstat 7 files changed, 18 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java	Thu Sep 13 15:13:45 2018 -0700
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java	Thu Sep 13 16:47:16 2018 -0700
@@ -3639,6 +3639,9 @@
 
     protected JCClassDecl recordDeclaration(JCModifiers mods, Comment dc) {
         int pos = token.pos;
+        if ((mods.flags & Flags.ABSTRACT) != 0) {
+            log.error(mods.pos, Errors.RecordCantBeAbstract);
+        }
         nextToken();
         mods.flags |= Flags.RECORD | Flags.STATIC | Flags.FINAL;
         Name name = typeName();
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties	Thu Sep 13 15:13:45 2018 -0700
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties	Thu Sep 13 16:47:16 2018 -0700
@@ -3337,6 +3337,9 @@
 ###
 # errors related to records
 
+compiler.err.record.cant.be.abstract=\
+    records cannot be abstract
+
 compiler.err.record.must.declare.at.least.one.field=\
     records must declare at least one field
 
--- a/test/langtools/tools/javac/datum/DatumShouldDeclareAtLeastOneFieldTest.java	Thu Sep 13 15:13:45 2018 -0700
+++ b/test/langtools/tools/javac/datum/DatumShouldDeclareAtLeastOneFieldTest.java	Thu Sep 13 16:47:16 2018 -0700
@@ -5,7 +5,7 @@
  */
 
 public class DatumShouldDeclareAtLeastOneFieldTest {
-    static abstract record D1() { }
+    record D1() { }
 
     static record D2() { }
 }
--- a/test/langtools/tools/javac/datum/DatumShouldDeclareAtLeastOneFieldTest.out	Thu Sep 13 15:13:45 2018 -0700
+++ b/test/langtools/tools/javac/datum/DatumShouldDeclareAtLeastOneFieldTest.out	Thu Sep 13 16:47:16 2018 -0700
@@ -1,3 +1,3 @@
-DatumShouldDeclareAtLeastOneFieldTest.java:8:33: compiler.err.record.must.declare.at.least.one.field
+DatumShouldDeclareAtLeastOneFieldTest.java:8:17: compiler.err.record.must.declare.at.least.one.field
 DatumShouldDeclareAtLeastOneFieldTest.java:10:24: compiler.err.record.must.declare.at.least.one.field
 2 errors
--- a/test/langtools/tools/javac/datum/Neg01.java	Thu Sep 13 15:13:45 2018 -0700
+++ b/test/langtools/tools/javac/datum/Neg01.java	Thu Sep 13 16:47:16 2018 -0700
@@ -5,7 +5,7 @@
  */
 
 public class Neg01 {
-    static abstract record Sup1(int x, int y) { }
+    static record Sup1(int x, int y) { }
 
     record Bad1(int x, int y, int z) extends Sup1(x, y) { } //can't extend
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/tools/javac/datum/RecordsCantBeAbstractTest.java	Thu Sep 13 16:47:16 2018 -0700
@@ -0,0 +1,7 @@
+/*
+ * @test /nodynamiccopyright/
+ * @summary smoke negative test for datum classes
+ * @compile/fail/ref=RecordsCantBeAbstractTest.out -XDrawDiagnostics RecordsCantBeAbstractTest.java
+ */
+
+abstract record RecordsCantBeAbstractTest(int i);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/tools/javac/datum/RecordsCantBeAbstractTest.out	Thu Sep 13 16:47:16 2018 -0700
@@ -0,0 +1,2 @@
+RecordsCantBeAbstractTest.java:7:1: compiler.err.record.cant.be.abstract
+1 error