8273257: jshell doesn't compile a sealed hierarchy with a sealed interface and a non-sealed leaf
Reviewed-by: vromero
This commit is contained in:
parent
f17ee0c5c7
commit
7b023a3f60
@ -5300,9 +5300,16 @@ public class Attr extends JCTree.Visitor {
|
|||||||
|
|
||||||
if (sealedSupers.isEmpty()) {
|
if (sealedSupers.isEmpty()) {
|
||||||
if ((c.flags_field & Flags.NON_SEALED) != 0) {
|
if ((c.flags_field & Flags.NON_SEALED) != 0) {
|
||||||
boolean hasErrorSuper = types.directSupertypes(c.type)
|
boolean hasErrorSuper = false;
|
||||||
|
|
||||||
|
hasErrorSuper |= types.directSupertypes(c.type)
|
||||||
.stream()
|
.stream()
|
||||||
.anyMatch(s -> s.tsym.kind == Kind.ERR);
|
.anyMatch(s -> s.tsym.kind == Kind.ERR);
|
||||||
|
|
||||||
|
ClassType ct = (ClassType) c.type;
|
||||||
|
|
||||||
|
hasErrorSuper |= !ct.isCompound() && ct.interfaces_field != ct.all_interfaces_field;
|
||||||
|
|
||||||
if (!hasErrorSuper) {
|
if (!hasErrorSuper) {
|
||||||
log.error(TreeInfo.diagnosticPositionFor(c, env.tree), Errors.NonSealedWithNoSealedSupertype(c));
|
log.error(TreeInfo.diagnosticPositionFor(c, env.tree), Errors.NonSealedWithNoSealedSupertype(c));
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* @test
|
* @test
|
||||||
* @bug 8246353
|
* @bug 8246353 8273257
|
||||||
* @summary Test sealed class in jshell
|
* @summary Test sealed class in jshell
|
||||||
* @modules jdk.jshell
|
* @modules jdk.jshell
|
||||||
* @build KullaTesting TestingInputStream ExpectedDiagnostic
|
* @build KullaTesting TestingInputStream ExpectedDiagnostic
|
||||||
@ -53,6 +53,16 @@ public class SealedClassesTest extends KullaTesting {
|
|||||||
assertEval("new I()");
|
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() {
|
public void testNonSealed() {
|
||||||
TypeDeclSnippet base = classKey(
|
TypeDeclSnippet base = classKey(
|
||||||
assertEval("sealed class B permits I {}",
|
assertEval("sealed class B permits I {}",
|
||||||
@ -63,4 +73,15 @@ public class SealedClassesTest extends KullaTesting {
|
|||||||
assertEval("class I2 extends I {}");
|
assertEval("class I2 extends I {}");
|
||||||
assertEval("new I2()");
|
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
|
* SealedCompilationTests
|
||||||
*
|
*
|
||||||
* @test
|
* @test
|
||||||
* @bug 8246353
|
* @bug 8246353 8273257
|
||||||
* @summary Negative compilation tests, and positive compilation (smoke) tests for sealed classes
|
* @summary Negative compilation tests, and positive compilation (smoke) tests for sealed classes
|
||||||
* @library /lib/combo /tools/lib
|
* @library /lib/combo /tools/lib
|
||||||
* @modules
|
* @modules
|
||||||
@ -727,6 +727,18 @@ public class SealedCompilationTests extends CompilationTestCase {
|
|||||||
""");
|
""");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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() {
|
public void testIllFormedNonSealed() {
|
||||||
for (String s : List.of(
|
for (String s : List.of(
|
||||||
"""
|
"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user