Skip to content
Permalink
Browse files
8273257: jshell doesn't compile a sealed hierarchy with a sealed inte…
…rface and a non-sealed leaf

Reviewed-by: vromero
  • Loading branch information
Jan Lahoda committed Sep 3, 2021
1 parent f17ee0c commit 7b023a3f607f44da1b13bc9d2884a5f13723d524
@@ -5300,9 +5300,16 @@ void attribClass(ClassSymbol c) throws CompletionFailure {

if (sealedSupers.isEmpty()) {
if ((c.flags_field & Flags.NON_SEALED) != 0) {
boolean hasErrorSuper = types.directSupertypes(c.type)
.stream()
.anyMatch(s -> s.tsym.kind == Kind.ERR);
boolean hasErrorSuper = false;

hasErrorSuper |= types.directSupertypes(c.type)
.stream()
.anyMatch(s -> s.tsym.kind == Kind.ERR);

ClassType ct = (ClassType) c.type;

hasErrorSuper |= !ct.isCompound() && ct.interfaces_field != ct.all_interfaces_field;

if (!hasErrorSuper) {
log.error(TreeInfo.diagnosticPositionFor(c, env.tree), Errors.NonSealedWithNoSealedSupertype(c));
}
@@ -23,7 +23,7 @@

/*
* @test
* @bug 8246353
* @bug 8246353 8273257
* @summary Test sealed class in jshell
* @modules jdk.jshell
* @build KullaTesting TestingInputStream ExpectedDiagnostic
@@ -53,6 +53,16 @@ public void testSealed() {
assertEval("new I()");
}

public void testInterface() {
TypeDeclSnippet base = classKey(
assertEval("sealed interface I permits C {}",
ste(MAIN_SNIPPET, Status.NONEXISTENT, Status.RECOVERABLE_NOT_DEFINED, false, null)));
assertEval("final class C implements I {}",
added(VALID),
ste(base, Status.RECOVERABLE_NOT_DEFINED, Status.VALID, true, null));
assertEval("new C()");
}

public void testNonSealed() {
TypeDeclSnippet base = classKey(
assertEval("sealed class B permits I {}",
@@ -63,4 +73,15 @@ public void testNonSealed() {
assertEval("class I2 extends I {}");
assertEval("new I2()");
}

public void testNonSealedInterface() {
TypeDeclSnippet base = classKey(
assertEval("sealed interface B permits C {}",
ste(MAIN_SNIPPET, Status.NONEXISTENT, Status.RECOVERABLE_NOT_DEFINED, false, null)));
assertEval("non-sealed class C implements B {}",
added(VALID),
ste(base, Status.RECOVERABLE_NOT_DEFINED, Status.VALID, true, null));
assertEval("class C2 extends C {}");
assertEval("new C2()");
}
}
@@ -25,7 +25,7 @@
* SealedCompilationTests
*
* @test
* @bug 8246353
* @bug 8246353 8273257
* @summary Negative compilation tests, and positive compilation (smoke) tests for sealed classes
* @library /lib/combo /tools/lib
* @modules
@@ -727,6 +727,18 @@ public void testNonSealedErroneousSuper() {
""");
}

public void testNonSealedErroneousSuperInterface() {
assertFail("compiler.err.cant.resolve",
d -> {
if (diags.keys().size() != 1) {
fail("Unexpected errors: " + diags.toString());
}
},
"""
non-sealed class C implements Undefined {}
""");
}

public void testIllFormedNonSealed() {
for (String s : List.of(
"""

1 comment on commit 7b023a3

@openjdk-notifier

This comment has been minimized.

Copy link

@openjdk-notifier openjdk-notifier bot commented on 7b023a3 Sep 3, 2021

Please sign in to comment.