changeset 49711:e454ab8936ba datum

all records are concrete and cannot extend any other record
author vromero
date Fri, 06 Apr 2018 14:34:19 -0400
parents 92f12a719e67
children 90609e9cd9f4
files src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java test/langtools/tools/javac/datum/CheckDatumMembersAccess.java test/langtools/tools/javac/datum/DataClassAsSuper.out test/langtools/tools/javac/datum/Neg01.java test/langtools/tools/javac/datum/Neg01.out test/langtools/tools/javac/datum/Pos01.java test/langtools/tools/javac/datum/SubDatumCannotPassDuplicateArgsToSuperTest.java test/langtools/tools/javac/datum/SubDatumCannotPassDuplicateArgsToSuperTest.out test/langtools/tools/javac/datum/SubDatumFieldsMustBeAPrefixOfParentTest.java test/langtools/tools/javac/datum/SubDatumFieldsMustBeAPrefixOfParentTest.out test/langtools/tools/javac/datum/UserDefinedMethodsTest.java
diffstat 12 files changed, 21 insertions(+), 118 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java	Fri Apr 06 13:30:02 2018 -0400
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java	Fri Apr 06 14:34:19 2018 -0400
@@ -1199,6 +1199,10 @@
                 mask &= ~(ABSTRACT | FINAL);
                 implicit |= implicitEnumFinalFlag(tree);
             }
+            if ((flags & RECORD) != 0) {
+                // records can't be declared abstract
+                mask &= ~ABSTRACT;
+            }
             // Imply STRICTFP if owner has STRICTFP set.
             implicit |= sym.owner.flags_field & STRICTFP;
             break;
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java	Fri Apr 06 13:30:02 2018 -0400
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java	Fri Apr 06 14:34:19 2018 -0400
@@ -3528,31 +3528,10 @@
 
         Map<Name, JCVariableDecl> optHeaderFields = headerFields(mods);
 
-        if (optHeaderFields.size() == 0) {
+        if (optHeaderFields.isEmpty()) {
             log.error(token.pos, Errors.RecordMustDeclareAtLeastOneField);
         }
 
-        JCExpression extending = null;
-        Set<Name> superFieldNames = new LinkedHashSet<>();
-        if (token.kind == EXTENDS) {
-            nextToken();
-            extending = parseType();
-            if (token.kind == LPAREN) {
-                accept(LPAREN);
-                while (token.kind != RPAREN) {
-                    Name id = ident();
-                    if (!superFieldNames.contains(id)) {
-                        superFieldNames.add(id);
-                    } else {
-                        log.error(token.pos, Errors.DuplicateArgumentToSuper(id));
-                    }
-                    if (token.kind == COMMA) {
-                        nextToken();
-                    }
-                }
-                accept(RPAREN);
-            }
-        }
         List<JCExpression> implementing = List.nil();
         if (token.kind == IMPLEMENTS) {
             nextToken();
@@ -3564,15 +3543,7 @@
         } else {
             accept(SEMI);
         }
-        optHeaderFields.values().stream()
-                .filter(t -> superFieldNames.contains(t.name))
-                .forEach(t -> t.getModifiers().flags |= Flags.HYPOTHETICAL);
         java.util.List<JCVariableDecl> fields = new ArrayList<>();
-        for (Name n : superFieldNames) {
-            JCVariableDecl field = optHeaderFields.get(n);
-            fields.add(field);
-            optHeaderFields.remove(n);
-        }
         for (JCVariableDecl field : optHeaderFields.values()) {
             fields.add(field);
         }
@@ -3591,7 +3562,7 @@
         for (int i = fields.size() - 1; i >= 0; i--) {
             defs = defs.prepend(fields.get(i));
         }
-        JCClassDecl result = toP(F.at(pos).ClassDef(mods, name, typarams, extending, implementing, defs));
+        JCClassDecl result = toP(F.at(pos).ClassDef(mods, name, typarams, null, implementing, defs));
         attach(result, dc);
         return result;
     }
--- a/test/langtools/tools/javac/datum/CheckDatumMembersAccess.java	Fri Apr 06 13:30:02 2018 -0400
+++ b/test/langtools/tools/javac/datum/CheckDatumMembersAccess.java	Fri Apr 06 14:34:19 2018 -0400
@@ -41,8 +41,6 @@
 
 public class CheckDatumMembersAccess {
 
-    abstract record abtractDatum(int AbstractFieldToSearchFor) {}
-
     record Datum(int AbstractFieldToSearchFor, int newField, non-final int nonFinalField) {}
 
     public static void main(String args[]) throws Throwable {
@@ -50,26 +48,9 @@
     }
 
     void run() throws Throwable {
-        checkAbstractDatum();
         checkNonAbstractDatum();
     }
 
-    void checkAbstractDatum() throws Throwable {
-        File testClasses = new File(System.getProperty("test.classes"));
-        File file = new File(testClasses,
-                CheckDatumMembersAccess.class.getName() + "$abtractDatum.class");
-        ClassFile classFile = ClassFile.read(file);
-        for (Field f : classFile.fields) {
-            if (f.getName(classFile.constant_pool).equals("AbstractFieldToSearchFor")) {
-                Assert.check((f.access_flags.flags & AccessFlags.ACC_PROTECTED) != 0, "fields of abstract datum should be protected");
-            }
-        }
-
-        for (Method m : classFile.methods) {
-            Assert.check((m.access_flags.flags & AccessFlags.ACC_PUBLIC) != 0, "methods of abstract datum should be public");
-        }
-    }
-
     void checkNonAbstractDatum() throws Throwable {
         File testClasses = new File(System.getProperty("test.classes"));
         File file = new File(testClasses,
--- a/test/langtools/tools/javac/datum/DataClassAsSuper.out	Fri Apr 06 13:30:02 2018 -0400
+++ b/test/langtools/tools/javac/datum/DataClassAsSuper.out	Fri Apr 06 14:34:19 2018 -0400
@@ -1,3 +1,6 @@
-DataClassAsSuper.java:10:30: compiler.err.cant.extend.record: (compiler.misc.bad.record.super)
-DataClassAsSuper.java:15:37: compiler.err.cant.extend.record: (compiler.misc.bad.record.super)
-2 errors
+DataClassAsSuper.java:10:21: compiler.err.expected: ';'
+DataClassAsSuper.java:10:36: compiler.err.expected: token.identifier
+DataClassAsSuper.java:15:28: compiler.err.expected: ';'
+DataClassAsSuper.java:15:37: compiler.err.invalid.meth.decl.ret.type.req
+DataClassAsSuper.java:15:41: compiler.err.expected: token.identifier
+5 errors
--- a/test/langtools/tools/javac/datum/Neg01.java	Fri Apr 06 13:30:02 2018 -0400
+++ b/test/langtools/tools/javac/datum/Neg01.java	Fri Apr 06 14:34:19 2018 -0400
@@ -7,28 +7,12 @@
 public class Neg01 {
     static abstract record Sup1(int x, int y) { }
 
-    record Bad1(int x, int y, int z) extends Sup1(x, y, z) { } //too many super args
-
-    record Bad2(int x, int z) extends Sup1(x) { } //too few super args
-
-    record Bad3(int x, int z) extends Sup1(x, z) { } //name mismatch
-
-    record Bad4(int x, double y) extends Sup1(x, y) { } //type mismatch
-
-    record Bad5(int x, int y) extends Sup1(x, y) {
-        Bad5(int x, int y) { super(x, y); } //error: explicit constructor and super header
-    }
+    record Bad1(int x, int y, int z) extends Sup1(x, y) { } //can't extend
 
     static class Sup2 { }
 
-    record Bad6(int x, int y) extends Object(x) { } //bad super header
-
-    record Bad7(int x, int y) extends Sup2 { } //non-datum superclass
-
     static record Sup3(int x, int y) { }
 
-    record Bad7(int x, int y) extends Sup2 { } //non-abstract datum superclass
-
     record Test(int x) {
         Test(int x, int y) {
             default(); //too few
--- a/test/langtools/tools/javac/datum/Neg01.out	Fri Apr 06 13:30:02 2018 -0400
+++ b/test/langtools/tools/javac/datum/Neg01.out	Fri Apr 06 14:34:19 2018 -0400
@@ -1,14 +1,5 @@
-Neg01.java:30:5: compiler.err.already.defined: kindname.class, Neg01.Bad7, kindname.class, Neg01
-Neg01.java:10:5: compiler.err.cant.apply.symbol: kindname.constructor, Sup1, int,int, int,int,int, kindname.class, Neg01.Sup1, (compiler.misc.arg.length.mismatch)
-Neg01.java:12:5: compiler.err.cant.apply.symbol: kindname.constructor, Sup1, int,int, int, kindname.class, Neg01.Sup1, (compiler.misc.arg.length.mismatch)
-Neg01.java:14:39: compiler.err.cant.extend.record: (compiler.misc.super.field.mismatch: int, y, int, z)
-Neg01.java:16:42: compiler.err.cant.extend.record: (compiler.misc.super.field.mismatch: int, y, double, y)
-Neg01.java:16:5: compiler.err.cant.apply.symbol: kindname.constructor, Sup1, int,int, int,double, kindname.class, Neg01.Sup1, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.possible.loss.of.precision: double, int))
-Neg01.java:18:39: compiler.err.cant.extend.record: (compiler.misc.bad.super.fields)
-Neg01.java:24:39: compiler.err.cant.extend.record: (compiler.misc.bad.record.super)
-Neg01.java:24:5: compiler.err.cant.apply.symbol: kindname.constructor, Object, compiler.misc.no.args, int, kindname.class, java.lang.Object, (compiler.misc.arg.length.mismatch)
-Neg01.java:26:39: compiler.err.cant.extend.record: (compiler.misc.bad.record.super)
-Neg01.java:34:20: compiler.err.cant.apply.symbol: kindname.constructor, Test, int, compiler.misc.no.args, kindname.class, Neg01.Test, (compiler.misc.arg.length.mismatch)
-Neg01.java:36:20: compiler.err.cant.apply.symbol: kindname.constructor, Test, int, int,int, kindname.class, Neg01.Test, (compiler.misc.arg.length.mismatch)
-Neg01.java:40:12: compiler.err.cant.resolve.location.args: kindname.method, default, , , (compiler.misc.location: kindname.class, Neg01.Test, null)
-13 errors
+Neg01.java:10:37: compiler.err.expected: ';'
+Neg01.java:10:46: compiler.err.invalid.meth.decl.ret.type.req
+Neg01.java:10:52: compiler.err.expected: token.identifier
+Neg01.java:10:55: compiler.err.expected: token.identifier
+4 errors
--- a/test/langtools/tools/javac/datum/Pos01.java	Fri Apr 06 13:30:02 2018 -0400
+++ b/test/langtools/tools/javac/datum/Pos01.java	Fri Apr 06 14:34:19 2018 -0400
@@ -36,9 +36,9 @@
         }
     }
 
-    static abstract record Sup(int x, int y) { }
+    static record Sup(int x, int y) { }
 
-    static record Foo(int x, int y, public int z) extends Sup(x, y);
+    static record Foo(int x, int y, public int z);
 
     public static void main(String[] args) {
         Foo foo = new Foo(1, 2, 3);
--- a/test/langtools/tools/javac/datum/SubDatumCannotPassDuplicateArgsToSuperTest.java	Fri Apr 06 13:30:02 2018 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,10 +0,0 @@
-/*
- * @test /nodynamiccopyright/
- * @summary smoke negative test for datum classes
- * @compile/fail/ref=SubDatumCannotPassDuplicateArgsToSuperTest.out -XDrawDiagnostics SubDatumCannotPassDuplicateArgsToSuperTest.java
- */
-
-public class SubDatumCannotPassDuplicateArgsToSuperTest {
-    abstract record D1(int x, int y) { }
-    record D2(int x, int y, int z) extends D1(x, x) { }
-}
--- a/test/langtools/tools/javac/datum/SubDatumCannotPassDuplicateArgsToSuperTest.out	Fri Apr 06 13:30:02 2018 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,2 +0,0 @@
-SubDatumCannotPassDuplicateArgsToSuperTest.java:9:51: compiler.err.duplicate.argument.to.super: x
-1 error
--- a/test/langtools/tools/javac/datum/SubDatumFieldsMustBeAPrefixOfParentTest.java	Fri Apr 06 13:30:02 2018 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,10 +0,0 @@
-/*
- * @test /nodynamiccopyright/
- * @summary smoke negative test for datum classes
- * @compile/fail/ref=SubDatumFieldsMustBeAPrefixOfParentTest.out -XDrawDiagnostics SubDatumFieldsMustBeAPrefixOfParentTest.java
- */
-
-public class SubDatumFieldsMustBeAPrefixOfParentTest {
-    abstract record D1(int x, int y) { }
-    record D2(int x, int y, int z) extends D1(y, x) { }
-}
--- a/test/langtools/tools/javac/datum/SubDatumFieldsMustBeAPrefixOfParentTest.out	Fri Apr 06 13:30:02 2018 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,2 +0,0 @@
-SubDatumFieldsMustBeAPrefixOfParentTest.java:9:44: compiler.err.cant.extend.record: (compiler.misc.super.field.mismatch: int, x, int, y)
-1 error
--- a/test/langtools/tools/javac/datum/UserDefinedMethodsTest.java	Fri Apr 06 13:30:02 2018 -0400
+++ b/test/langtools/tools/javac/datum/UserDefinedMethodsTest.java	Fri Apr 06 14:34:19 2018 -0400
@@ -34,13 +34,7 @@
 
 public class UserDefinedMethodsTest {
 
-    static abstract record Sup(int x) {
-        String foo() {
-            return "Sup.foo";
-        }
-    }
-
-    static record Foo(int x, int y, public int z) extends Sup(x) {
+    static record Foo(int x, int y, public int z) {
         @Override
         public String toString() {
             return "Foo(x=#x, y=#y, z=#z)".replaceAll("#x", "" + x).replaceAll("#y", "" + y).replaceAll("#z", "" + z);
@@ -55,7 +49,6 @@
             return "bar";
         }
 
-        @Override
         String foo() {
             return "Foo.foo";
         }