Skip to content
Permalink
Browse files
8266645: javac should not check for sealed supertypes in intersection…
… types

Reviewed-by: mcimadamore
  • Loading branch information
Vicente Romero committed May 7, 2021
1 parent 74fecc0 commit 946b0fe19a8af88a0f0451c86ce4d4790360bb83
@@ -5197,16 +5197,18 @@ void attribClass(ClassSymbol c) throws CompletionFailure {
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 @@ void f(A.B a, A<Object> b) {
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> {}
"""
);
}
}

1 comment on commit 946b0fe

@openjdk-notifier

This comment has been minimized.

Copy link

@openjdk-notifier openjdk-notifier bot commented on 946b0fe May 7, 2021

Please sign in to comment.