8266645: javac should not check for sealed supertypes in intersection types
Reviewed-by: mcimadamore
This commit is contained in:
parent
74fecc070a
commit
946b0fe19a
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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> {}
|
||||
"""
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user