-
Notifications
You must be signed in to change notification settings - Fork 136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[sealed] ECJ rejects casting from a sealed interface that permits a non-sealed class #3184
Comments
For the cast from Only instances possible for Given Java does not allow multiple inheritance for super classes, there cannot be a common descendent for @stephan-herrmann - do you disagree ? See also #2709 (comment) If the analysis is correct, this needs to be raised with Oracle for clarification. @jarthana - FYI. Key question is: Can there be a type that is a subtype of |
Question raised here: https://mail.openjdk.org/pipermail/compiler-dev/2024-October/028344.html Let's wait for an answer. |
No, I don't see that being allowed. |
We have a confirmation that this is a javac bug - see https://mail.openjdk.org/pipermail/compiler-dev/2024-October/028367.html |
@srikanth-sankaran This case could be related to this issue? public class Main {
class C {}
sealed interface I<T extends C> permits C1, C2 {
T op();
}
final class C1 extends C implements I<C1> {
@Override
public C1 op() {
return new C1();
}
}
final class C2 extends C implements I<C2> {
@Override
public C2 op() {
return new C2();
}
}
C getC() {
return new C2();
}
C1 getC1() {
return new C1();
}
public void test() {
// javac: no error
// eclipse: Incompatible conditional operand types Main.C and Main.I<?>Java(16777232)
var a = getC();
if (a instanceof I<?> i) {
i.op();
}
// javac: Pattern type 'I<?>' is a supertype of expression type 'Main. C1'
// eclipse: no error
var b = getC1();
if (b instanceof I<?> i) {
i.op();
}
}
} |
Hello @davidnussio - you haven't mentioned which version of Eclipse you are on and which version of javac you are on. Both must be very old. JDK23 and Eclipse master/HEAD both compile this program The javac error I think you could be using JDK18 or earlier ? Likewise Eclipse compiles this code as of at least 4.29 and upto top of trunk. Since ECJ master HEAD agrees with JDK23 I don't think there is any action called for other than for you to consider an upgrade |
This code produces compilation errors:
This cast and comparison should be allowed since NonSealedClass is non-sealed. This code is accepted by Javac.
If I alter the class definition to this, then both compilers report error:
final class NonSealedClass implements SealedInterface {}
The text was updated successfully, but these errors were encountered: