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

[compiler] Unnecessary cast warning is not detected when casting a bound generic type to its super type #2470

Closed
stephan-herrmann opened this issue May 21, 2024 · 0 comments · Fixed by #2471
Assignees

Comments

@stephan-herrmann
Copy link
Contributor

stephan-herrmann commented May 21, 2024

From https://bugs.eclipse.org/bugs/show_bug.cgi?id=517235

The following casts are unnecessary:

public class UnnecessaryCasts<T extends C> {
    void m(T t) {
        C c = t;

        ((C) t).x();
        ((I) t).x();
        ((I) c).x();
    }
}

interface I {
    void x();
}
class C implements I {
    @Override
    public void x() {}
}

Yet, the Eclipse compiler doesn't report them, and doesn't offer a quick fix to remove them.

@stephan-herrmann stephan-herrmann self-assigned this May 21, 2024
stephan-herrmann added a commit to stephan-herrmann/eclipse.jdt.core that referenced this issue May 21, 2024
stephan-herrmann added a commit to stephan-herrmann/eclipse.jdt.core that referenced this issue Jun 18, 2024
stephan-herrmann added a commit to stephan-herrmann/eclipse.jdt.core that referenced this issue Jun 20, 2024
generic type to its super type

strict analysis: test if removing the cast would change overload
resolution.

fixes eclipse-jdt#2470
robstryker pushed a commit to robstryker/eclipse.jdt.core that referenced this issue Jul 18, 2024
generic type to its super type

strict analysis: test if removing the cast would change overload
resolution.

fixes eclipse-jdt#2470
gayanper pushed a commit to gayanper/eclipse.jdt.core that referenced this issue Sep 7, 2024
generic type to its super type

strict analysis: test if removing the cast would change overload
resolution.

fixes eclipse-jdt#2470
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant