changeset 57918:5fbd6bd20a5b records-and-sealed

local classes cant extend sealed classes
author vromero
date Thu, 10 Oct 2019 22:23:26 -0400
parents a6b0ad4c98ab
children d45c1a111e21
files 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/sealed/SealedCompilationTests.java
diffstat 3 files changed, 16 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/TypeEnter.java	Thu Oct 10 22:08:39 2019 -0400
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/TypeEnter.java	Thu Oct 10 22:23:26 2019 -0400
@@ -875,6 +875,10 @@
                 log.error(tree, Errors.NonSealedWithNoSealedSupertype);
             }
 
+            if (hasSuperTypesInSealedHierarchy && tree.sym.isLocal()) {
+                log.error(tree, Errors.LocalClassesCantExtendSealed);
+            }
+
             if (hasSuperTypesInSealedHierarchy && !anySuperInSameCUIsSealed) {
                 // that supertype most have a permits clause allowing this class to extend it
                 List<Type> closureOutsideOfSameCU = types.closure(tree.sym.type).stream()
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties	Thu Oct 10 22:08:39 2019 -0400
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties	Thu Oct 10 22:23:26 2019 -0400
@@ -3429,6 +3429,9 @@
 compiler.err.sealed.or.non.sealed.local.classes.not.allowed=\
     sealed or non-sealed local classes are not allowed
 
+compiler.err.local.classes.cant.extend.sealed=\
+    local classes cannot extend sealed classes
+
 ###
 # errors related to records
 
--- a/test/langtools/tools/javac/sealed/SealedCompilationTests.java	Thu Oct 10 22:08:39 2019 -0400
+++ b/test/langtools/tools/javac/sealed/SealedCompilationTests.java	Thu Oct 10 22:23:26 2019 -0400
@@ -235,16 +235,15 @@
     }
 
     public void testLocalCantExtendSealed() {
-        // @@@ Currently failing
-//        for (String s : List.of(
-//                """
-//                sealed class C {
-//                    void m() {
-//                        final class D extends C { }
-//                    }
-//                }
-//                """))
-//            assertFail("compiler.err.cant.inherit.from.sealed", s);
+        for (String s : List.of(
+                """
+                sealed class C {
+                    void m() {
+                        final class D extends C { }
+                    }
+                }
+                """))
+            assertFail("compiler.err.local.classes.cant.extend.sealed", s);
     }
 
     public void testSealedInterfaceAndAbstracClasses() {