RFR: 8343580: Type error with inner classes of generic classes in functions generic by outer [v2]
Aggelos Biboudis
abimpoudis at openjdk.org
Thu May 22 09:10:39 UTC 2025
> javac determines erroneously that `getter` has a raw type (`G.Getter`). The type of `getter` is deduced as the raw type `Getters<T>.Getter` by javac. Thus, the `Object` in the following example. The question is whether it should be treated as raw or not in the scenario where the qualifying type *is* a type parameter, as in `G.Getter`. In this case `Getter` is inherited from the supertype `Getters<T>`:
>
>
> static abstract class Getters<T> {
> abstract class Getter {
> abstract T get();
> }
> }
>
> static class Usage<T, G extends Getters<T>> {
> public T test(G.Getter getter) {
> return getter.get(); // incompatible types: Object cannot be converted to T
> }
> }
>
>
> It seems that this is a compiler bug. According to 4.8 Raw Types a “rare” type occurs when the inner is a partially raw type but the definition of Getter doesn’t take any type variables, so this is not a case of a "rare" type. `G.Getter` describes a type with a qualifying type being a type parameter which is not raw and moreover there is an instantiation of its bound. Simply not looking into the bounds of `G` seems like a compiler bug.
Aggelos Biboudis has updated the pull request incrementally with one additional commit since the last revision:
Address review
-------------
Changes:
- all: https://git.openjdk.org/jdk/pull/25346/files
- new: https://git.openjdk.org/jdk/pull/25346/files/d2d59f9a..e228c004
Webrevs:
- full: https://webrevs.openjdk.org/?repo=jdk&pr=25346&range=01
- incr: https://webrevs.openjdk.org/?repo=jdk&pr=25346&range=00-01
Stats: 22 lines in 2 files changed: 19 ins; 0 del; 3 mod
Patch: https://git.openjdk.org/jdk/pull/25346.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/25346/head:pull/25346
PR: https://git.openjdk.org/jdk/pull/25346
More information about the compiler-dev
mailing list