Skip to content

Commit 946b0fe

Browse files
author
Vicente Romero
committedMay 7, 2021
8266645: javac should not check for sealed supertypes in intersection types
Reviewed-by: mcimadamore
1 parent 74fecc0 commit 946b0fe

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed
 

‎src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java

+11-9
Original file line numberDiff line numberDiff line change
@@ -5197,16 +5197,18 @@ void attribClass(ClassSymbol c) throws CompletionFailure {
51975197
log.error(TreeInfo.diagnosticPositionFor(c, env.tree), Errors.LocalClassesCantExtendSealed(c.isAnonymous() ? Fragments.Anonymous : Fragments.Local));
51985198
}
51995199

5200-
for (ClassSymbol supertypeSym : sealedSupers) {
5201-
if (!supertypeSym.permitted.contains(c.type.tsym)) {
5202-
log.error(TreeInfo.diagnosticPositionFor(c.type.tsym, env.tree), Errors.CantInheritFromSealed(supertypeSym));
5200+
if (!c.type.isCompound()) {
5201+
for (ClassSymbol supertypeSym : sealedSupers) {
5202+
if (!supertypeSym.permitted.contains(c.type.tsym)) {
5203+
log.error(TreeInfo.diagnosticPositionFor(c.type.tsym, env.tree), Errors.CantInheritFromSealed(supertypeSym));
5204+
}
5205+
}
5206+
if (!c.isNonSealed() && !c.isFinal() && !c.isSealed()) {
5207+
log.error(TreeInfo.diagnosticPositionFor(c, env.tree),
5208+
c.isInterface() ?
5209+
Errors.NonSealedOrSealedExpected :
5210+
Errors.NonSealedSealedOrFinalExpected);
52035211
}
5204-
}
5205-
if (!c.isNonSealed() && !c.isFinal() && !c.isSealed()) {
5206-
log.error(TreeInfo.diagnosticPositionFor(c, env.tree),
5207-
c.isInterface() ?
5208-
Errors.NonSealedOrSealedExpected :
5209-
Errors.NonSealedSealedOrFinalExpected);
52105212
}
52115213
}
52125214

‎test/langtools/tools/javac/sealed/SealedCompilationTests.java

+12
Original file line numberDiff line numberDiff line change
@@ -1254,4 +1254,16 @@ void f(A.B a, A<Object> b) {
12541254
assertOK(s);
12551255
}
12561256
}
1257+
1258+
public void testIntersectionWithSealedClasses() {
1259+
assertOK(
1260+
"""
1261+
class A { }
1262+
sealed interface I permits B { }
1263+
final class B extends A implements I { }
1264+
1265+
class Foo<X extends A & I> {}
1266+
"""
1267+
);
1268+
}
12571269
}

1 commit comments

Comments
 (1)

openjdk-notifier[bot] commented on May 7, 2021

@openjdk-notifier[bot]
Please sign in to comment.