8266645: javac should not check for sealed supertypes in intersection types

Reviewed-by: mcimadamore
This commit is contained in:
Vicente Romero 2021-05-07 14:38:18 +00:00
parent 74fecc070a
commit 946b0fe19a
2 changed files with 23 additions and 9 deletions

View File

@ -5197,16 +5197,18 @@ public class Attr extends JCTree.Visitor {
log.error(TreeInfo.diagnosticPositionFor(c, env.tree), Errors.LocalClassesCantExtendSealed(c.isAnonymous() ? Fragments.Anonymous : Fragments.Local));
}
for (ClassSymbol supertypeSym : sealedSupers) {
if (!supertypeSym.permitted.contains(c.type.tsym)) {
log.error(TreeInfo.diagnosticPositionFor(c.type.tsym, env.tree), Errors.CantInheritFromSealed(supertypeSym));
if (!c.type.isCompound()) {
for (ClassSymbol supertypeSym : sealedSupers) {
if (!supertypeSym.permitted.contains(c.type.tsym)) {
log.error(TreeInfo.diagnosticPositionFor(c.type.tsym, env.tree), Errors.CantInheritFromSealed(supertypeSym));
}
}
if (!c.isNonSealed() && !c.isFinal() && !c.isSealed()) {
log.error(TreeInfo.diagnosticPositionFor(c, env.tree),
c.isInterface() ?
Errors.NonSealedOrSealedExpected :
Errors.NonSealedSealedOrFinalExpected);
}
}
if (!c.isNonSealed() && !c.isFinal() && !c.isSealed()) {
log.error(TreeInfo.diagnosticPositionFor(c, env.tree),
c.isInterface() ?
Errors.NonSealedOrSealedExpected :
Errors.NonSealedSealedOrFinalExpected);
}
}

View File

@ -1254,4 +1254,16 @@ public class SealedCompilationTests extends CompilationTestCase {
assertOK(s);
}
}
public void testIntersectionWithSealedClasses() {
assertOK(
"""
class A { }
sealed interface I permits B { }
final class B extends A implements I { }
class Foo<X extends A & I> {}
"""
);
}
}