changeset 60089:6458f95494be amber-demo-II

Automatic merge with sealed-types
author mcimadamore
date Thu, 27 Feb 2020 18:55:41 +0000
parents 749031d7910f 02506a5c9735
children 67525d425cf7
files test/langtools/tools/javac/sealed/SealedCompilationTests.java
diffstat 3 files changed, 83 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/tools/javac/diags/examples/PermitsCantListDeclaringClass.java	Thu Feb 27 18:55:41 2020 +0000
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2020, 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.type.listed.in.permits.is.same.class.or.supertype
+// key: compiler.misc.same.class
+// key: compiler.note.preview.filename
+// key: compiler.note.preview.recompile
+// options: --enable-preview -source ${jdk.version}
+
+sealed class C permits C {}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/tools/javac/diags/examples/PermitsCantListSuperType.java	Thu Feb 27 18:55:41 2020 +0000
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2020, 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.type.listed.in.permits.is.same.class.or.supertype
+// key: compiler.misc.supertype
+// key: compiler.note.preview.filename
+// key: compiler.note.preview.recompile
+// options: --enable-preview -source ${jdk.version}
+
+interface I {}
+
+sealed class C implements I permits I {}
--- a/test/langtools/tools/javac/sealed/SealedCompilationTests.java	Thu Feb 27 05:05:42 2020 +0000
+++ b/test/langtools/tools/javac/sealed/SealedCompilationTests.java	Thu Feb 27 18:55:41 2020 +0000
@@ -186,6 +186,27 @@
                 "}");
     }
 
+    public void testTypeInPermitsIsSameClassOrSuper() {
+        assertFail("compiler.err.type.listed.in.permits.is.same.class.or.supertype",
+                """
+                sealed class Sealed permits Sealed {}
+                """
+                );
+        assertFail("compiler.err.type.listed.in.permits.is.same.class.or.supertype",
+                """
+                interface I {}
+                sealed class Sealed implements I permits I {}
+                """
+                );
+        assertFail("compiler.err.type.listed.in.permits.is.same.class.or.supertype",
+                """
+                interface I {}
+                interface I2 extends I {}
+                sealed class Sealed implements I2 permits I {}
+                """
+                );
+    }
+
     /* It is a compile-time error if a class declaration has more than one of the class modifiers
      * sealed, non-sealed and final
      */