RFR: 8295019: Cannot call a method with a parameter of a local class declared in a lambda [v2]

Maurizio Cimadamore mcimadamore at openjdk.org
Thu Feb 2 00:25:26 UTC 2023


On Thu, 2 Feb 2023 00:11:18 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

>> Vicente Romero has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   some experiments, close to a stable version
>
> src/jdk.compiler/share/classes/com/sun/tools/javac/comp/DeferredAttr.java line 462:
> 
>> 460:     }
>> 461: 
>> 462:     boolean hasTypeDeclaration(JCLambda lambda) {
> 
> This is a good start.
> A couple of comments:
> * I believe this problem is more general than just lambdas (e.g. switch expression probably suffers from that as well)
> * It would be better to write a single visitor which does everything in a single pass, rather than visit every statement in a block explicitly (after all, that's what the visitor is gonna do anyways). I even believe the visitor should recurse into everything (including nested lambdas and classes - after all, a class _nested_ in a local class might have a type which is then referred by the lambda return type!).

This is the equivalent bug with switch expression:


class LocalClassDeclaredInsideSwitchTest {
    void run(int i) {}

    void m(int o) {
        run(switch(o) {
          case 1 -> {
            class C {
                static int takeC(C c) {}
                static C giveC() {
                    return null;
                }
            }
            yield C.takeC(C.giveC());
         }
         default -> throw new AssertionError();
       });
    }
}


We should come up with a fix that is general enough to handle all these cases.

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

PR: https://git.openjdk.org/jdk/pull/12303


More information about the compiler-dev mailing list