Skip to content

Commit

Permalink
8294550: Sealed check for casts isn't applied to array components
Browse files Browse the repository at this point in the history
Reviewed-by: vromero
  • Loading branch information
lahodaj committed Oct 20, 2022
1 parent c08ff2c commit 78dc497
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1852,7 +1852,7 @@ public Boolean visitArrayType(ArrayType t, Type s) {
if (elemtype(t).isPrimitive() || elemtype(s).isPrimitive()) {
return elemtype(t).hasTag(elemtype(s).getTag());
} else {
return visit(elemtype(t), elemtype(s));
return isCastable(elemtype(t), elemtype(s), warnStack.head);
}
default:
return false;
Expand Down
26 changes: 25 additions & 1 deletion test/langtools/tools/javac/sealed/SealedCompilationTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* SealedCompilationTests
*
* @test
* @bug 8246353 8273257
* @bug 8246353 8273257 8294550
* @summary Negative compilation tests, and positive compilation (smoke) tests for sealed classes
* @library /lib/combo /tools/lib
* @modules
Expand Down Expand Up @@ -1146,6 +1146,19 @@ void test () {
C c = (C) i;
}
}
""",
//JDK-8294550:
"""
interface I {}
sealed class C permits D {}
final class D extends C {}
class Test {
void test () {
C[] c = null;
I[] i = (I[]) c;
}
}
"""
)) {
assertFail("compiler.err.prob.found.req", s);
Expand Down Expand Up @@ -1234,6 +1247,17 @@ void f(A.B a, A<Object> b) {
a = (A.B)b;
}
}
""",
"""
sealed class C permits D {}
final class D extends C {}
class Test {
void test () {
C[] c = null;
D[] d = (D[]) c;
}
}
"""
)) {
assertOK(s);
Expand Down

1 comment on commit 78dc497

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.