Skip to content
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 types] Proper sealing of hierarchy rejected in incremental builds if permitted class is generic #3488

Closed
konczdev opened this issue Dec 26, 2024 · 7 comments · Fixed by #3490
Assignees
Labels
bug Something isn't working compiler Eclipse Java Compiler (ecj) related issues regression Something was broken by a previous change
Milestone

Comments

@konczdev
Copy link

The compiler incorrectly reports that a generic class is not a permitted subtype in a sealed class hierarchy, even when it's explicitly listed in the permits clause.

Minimal example to reproduce:

public sealed abstract class Message permits Request {
    private final String id;
    
    protected Message(String id) {
        this.id = id;
    }
}

public final class Request<T> extends Message {  // Error here
    private final T payload;
    
    public Request(String id, T payload) {
        super(id);
        this.payload = payload;
    }
}

Expected behavior:

  • The code should compile since Request is explicitly listed in Message's permits clause
  • The addition of generic type parameters should not affect the sealed class hierarchy

Actual behavior:

  • Compiler error: "The class Request cannot extend the class Message as it is not a permitted subtype of Message"
  • Removing the generic type parameter makes the error disappear

This appears to be a bug in handling generic type parameters within sealed class hierarchies.

Java version: 17 (Eclipse Temurin jdk-17.0.11+9)

Eclipse IDE for Eclipse Committers (includes Incubating components)

Version: 2024-12 (4.34.0)
Build id: 20241128-0757

@srikanth-sankaran srikanth-sankaran self-assigned this Dec 26, 2024
@srikanth-sankaran
Copy link
Contributor

This appears to be a bug in handling generic type parameters within sealed class hierarchies.

Java version: 17 (Eclipse Temurin jdk-17.0.11+9)

Eclipse IDE for Eclipse Committers (includes Incubating components)

Version: 2024-12 (4.34.0) Build id: 20241128-0757

I don't think these version numbers look right.

This problem is not reproducible on Eclipse SDK 4.33 or 4.34 or on master/HEAD.

I intend to close this as not reproducible.

It is likely the Temurin build is using an ancient version of JDT plugins.

@konczdev
Copy link
Author

@srikanth-sankaran
Here is a freshly downloaded Eclipse IDE for Java Developers

image

@konczdev
Copy link
Author

JDT plugin versions:
image

@konczdev
Copy link
Author

@srikanth-sankaran I made an observation: if I clean the project the error is gone until I touch the affected file and save. After saving the error shows.

@srikanth-sankaran
Copy link
Contributor

@srikanth-sankaran I made an observation: if I clean the project the error is gone until I touch the affected file and save. After saving the error shows.

Thanks for that tip - reproduced. Looks like a defect in incremental building. Investigating ...

@srikanth-sankaran srikanth-sankaran changed the title False positive error with generic type parameters in sealed class hierarchies [Sealed types] Proper sealing of hierarchy rejected in incremental builds if permitted class is generic Dec 27, 2024
@srikanth-sankaran srikanth-sankaran added this to the 4.35 M1 milestone Dec 27, 2024
@srikanth-sankaran srikanth-sankaran added bug Something isn't working regression Something was broken by a previous change compiler Eclipse Java Compiler (ecj) related issues labels Dec 27, 2024
@srikanth-sankaran
Copy link
Contributor

Works fine in 3.43. Mea cupla :-(

@konczdev
Copy link
Author

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working compiler Eclipse Java Compiler (ecj) related issues regression Something was broken by a previous change
Projects
None yet
2 participants