RFR: 8319196: ExecutableElement.getReceiverType doesn't return receiver types for methods loaded from bytecode [v2]

Liam Miller-Cushon cushon at openjdk.org
Fri Nov 3 01:24:08 UTC 2023


On Fri, 3 Nov 2023 00:18:33 GMT, Chen Liang <liach at openjdk.org> wrote:

>> Liam Miller-Cushon has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   Add a null check, update affected tests
>
> src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symbol.java line 2289:
> 
>> 2287:                 return enclosingType.getEnclosingType();
>> 2288:             }
>> 2289:             if (!isStatic()) {
> 
> Just curious, what happens in such a scenario:
> 
> public class Outer {
>   public static void work() {
>     class Local {
>       Local() {} // <- what's the implicitReceiverType here?
>     }
>   }
> }
> 
> FYI javac currently is not marking such local classes in static methods as `static` in its `InnerClasses` attribute.

Good question! I debugged that example, and `getEnclosingType()` returns `NoType`, which I think is what we want.

This is the logic that initializes the enclosing type and handles local classes:

https://github.com/openjdk/jdk/blob/c788160f8acea7b58b54ad857b601bb7ffb53f8e/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Enter.java#L508-L519

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/16482#discussion_r1380962373


More information about the compiler-dev mailing list