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

Chen Liang liach at openjdk.org
Fri Nov 3 00:22:03 UTC 2023


On Thu, 2 Nov 2023 19:36:19 GMT, Liam Miller-Cushon <cushon at openjdk.org> wrote:

>> Hello,
>> 
>> Please consider this fix for [JDK-8319196: ExecutableElement.getReceiverType doesn't return receiver types for methods loaded from bytecode](https://bugs.openjdk.org/browse/JDK-8319196).
>> 
>> As discussed in [the accompanying CSR](https://bugs.openjdk.org/browse/JDK-8319330), `ExecutableElement.getReceiverType()` and `ExecutableType.getReceiverType()` currently returns `NoType` unless the receiver parameter syntax was present in source, which also means that `getReceiverType()` doesn't work for methods loaded from class files.
>> 
>> This fix updates the implementation to return the implicit receiver type of methods that do not explicitly declare a receiver parameter in source, including for methods that were loaded from class files.
>
> 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 2285:

> 2283:                 return null;
> 2284:             }
> 2285:             Type enclosingType = enclClass().type;

Suggestion:

            Type enclosingType = enclosingClass.type;

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.

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

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


More information about the compiler-dev mailing list