RFR: 8357653: Inner classes of type parameters emitted as raw types in signatures [v16]
Chen Liang
liach at openjdk.org
Fri Jul 11 15:37:44 UTC 2025
On Fri, 11 Jul 2025 13:39:59 GMT, Aggelos Biboudis <abimpoudis at openjdk.org> wrote:
>> There are various occasions that the qualifier of an _inner type_ needs to be normalized.
>>
>> Briefly:
>>
>> - This occurs when there is an explicit type application in the signature of the method or a type application operation or when type checking an expression operation (e.g., `G.Getter` in the first example, `M.B<?>` in the second example).
>> - The reference to an inner type may not be explicitly qualified (e.g., `B<?>` which is not qualified but its type needs be calculated as seen from `A<String>.B<?>`).
>>
>> Semi-formally:
>>
>> - A type reference is simple name `R`:
>>
>> - `R` is a non-inner class type, nothing to do
>> - `R` is an inner class type, we need to find an implicit type qualifier `S<T>.R`, where `S` is the class in which `R` is enclosed
>> - `R` is an array type `A[]`, repeat the analysis for the simple type name `A`, and then use the implicit type qualifier to rewrite the array
>>
>> - A type reference is a qualified name `Q.R`
>>
>> - find the supertype of `Q`, namely `S<T>`, where `S` is the class in which `R` is enclosed
>>
>>
>>
>> // example 1
>> static class Usage1<T, G extends Getters<T>> {
>> public T test(G.Getter getter) {
>> return getter.get();
>> }
>> }
>>
>> // example 2
>> class A<T> {
>> protected class B<V> {}
>>
>> public static <T, M extends A<T>> void f(Object g) {
>> @SuppressWarnings("unchecked")
>> M.B<?> mapping = (M.B<?>) g;
>> }
>> }
>>
>> // example 3
>> class A<T> {
>> class B<W> {
>> public T rett() { return null; }
>> }
>> }
>>
>> class C extends A<String> {
>> static class D {
>> {
>> B<?> b = null;
>> String s = b.rett();
>> }
>> }
>> }
>
> Aggelos Biboudis has updated the pull request incrementally with one additional commit since the last revision:
>
> Fix example
Bikeshedding
src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java line 2240:
> 2238: ///
> 2239: /// The sequence of types starts with `t` and the next type in the sequence
> 2240: /// is obtained by calling `getEnclosingType()` on the previous type in the
Suggestion:
/// is obtained by calling `getEnclosingType()` on the previous type in the
src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java line 2248:
> 2246: /// seen as super of in the sequence `Outer.Sub.I`.
> 2247: ///
> 2248: /// Can `Sup` be seen as super of `Outer.Sub.I`? No. Going to the next enclosing type .
Suggestion:
/// Can `Sup` be seen as super of `Outer.Sub.I`? No. Going to the next enclosing type.
src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java line 2249:
> 2247: ///
> 2248: /// Can `Sup` be seen as super of `Outer.Sub.I`? No. Going to the next enclosing type .
> 2249: /// Can `Sup` be seen as super of `Outer.Sub`? Yes! It’s outer results in `Sup<String>`.
Suggestion:
/// Can `Sup` be seen as super of `Outer.Sub`? Yes! Its outer results in `Sup<String>`.
src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java line 2264:
> 2262: /// ```
> 2263: ///
> 2264: /// @implNote this is typically used to compute the implicit qualifier in a
Suggestion:
/// @implNote This is typically used to compute the implicit qualifier in a
This is a new paragraph in a block tag
src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java line 2269:
> 2267: /// @param t a type
> 2268: /// @param sym a symbol
> 2269: ///
Suggestion:
src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java line 2289:
> 2287: /// Example: The type expression `B` is implicitly qualified and the
> 2288: /// proper generic outer needs to be retrieved. Its site is `C.D` and its
> 2289: /// outer type is `A`.`asEnclosingSuper` will use the enclosing classes to
Suggestion:
/// outer type is `A`. `asEnclosingSuper` will use the enclosing classes to
src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java line 2306:
> 2304: /// ```
> 2305: ///
> 2306: /// @implNote this is typically used to compute the implicit qualifier in
Suggestion:
/// @implNote This is typically used to compute the implicit qualifier in
src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java line 2311:
> 2309: /// @param t a type
> 2310: /// @param sym a symbol
> 2311: ///
Suggestion:
-------------
PR Review: https://git.openjdk.org/jdk/pull/25451#pullrequestreview-3010786097
PR Review Comment: https://git.openjdk.org/jdk/pull/25451#discussion_r2201036914
PR Review Comment: https://git.openjdk.org/jdk/pull/25451#discussion_r2201040024
PR Review Comment: https://git.openjdk.org/jdk/pull/25451#discussion_r2201040868
PR Review Comment: https://git.openjdk.org/jdk/pull/25451#discussion_r2201042473
PR Review Comment: https://git.openjdk.org/jdk/pull/25451#discussion_r2201043202
PR Review Comment: https://git.openjdk.org/jdk/pull/25451#discussion_r2201044899
PR Review Comment: https://git.openjdk.org/jdk/pull/25451#discussion_r2201046326
PR Review Comment: https://git.openjdk.org/jdk/pull/25451#discussion_r2201046562
More information about the compiler-dev
mailing list