[lworld] RFR: 8367323: [lworld] javac is rejecting valid code after fix for JDK-8359370
Maurizio Cimadamore
mcimadamore at openjdk.org
Fri Sep 12 15:19:00 UTC 2025
On Thu, 11 Sep 2025 17:35:55 GMT, Vicente Romero <vromero at openjdk.org> wrote:
>> src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java line 1477:
>>
>>> 1475: * the compiler
>>> 1476: */
>>> 1477: return sym.kind != MTH || !insideClassDef;
>>
>> I think the "right" thing to do here seems to have to do with membership and whether the access is unqualified or not.
>>
>> E.g.
>> * if we are in the prologue of `A`, and we see a call to `m()`, and `m()` is a member of `A`, then we should fail
>> * if we are in a class `B` inside the prologue of `A`, and we see a call to `m()`, and `m()` is a member of `B`, then it should be ok
>> * if we are in a class `B` inside the prologue of `A`, and we see a call to `m()`, and `m()` is a member of _both_ `B` and `A`, then it should be ok
>> * if we are in a class `B` inside the prologue of `A`, and we see a call to `m()`, and `m()` is a member of `A` then it should fail
>>
>> The problem seems to be that, by the time we hit the `isEarlyReference` method, we no longer know the "current class" -- so we always check membership against the "outer" class whose prologue we're inspecting.
>
> I have updated the PR there is a test case that was failing before but now is passing:
>
> class Test {
> public int xx;
>
> Test() {
> int i = new Test(){
> void foo() {
> System.err.println(xx);
> }
> }.xx;
> super();
> }
> }
>
> I think that it is correct that we accept this code as in both cases we are accessing the `xx` field inherited by the anonymous class
yes, the accessed `xx` is _another_ field
-------------
PR Review Comment: https://git.openjdk.org/valhalla/pull/1567#discussion_r2344048138
More information about the valhalla-dev
mailing list