RFR: 8279290: symbol not found error, implicit lambdas and diamond constructor invocations

Vicente Romero vromero at openjdk.java.net
Wed Jan 12 16:51:28 UTC 2022

On Thu, 6 Jan 2022 05:42:49 GMT, Vicente Romero <vromero at openjdk.org> wrote:

> Please review this PR which is fixing a bug caused by scope sharing. In particular for code like:
> class Test {
>     static class B<T>{}
>     static class A1 {
>         <T> A1(Consumer<T> cons) {}
>     }
>     void foo() {
>         new A1(findMe ->
>                 new B<>() {{
>                     System.out.println(findMe); // javac is failing here with symbol not found for findMe
>                 }});
>     }
> }
> the reason for the error is that when attributing the diamond constructor invocation, a listener is registered in the current inference context. But the scope inside the environment passed to the listener is shared with the implicit lambda and once the lambda has been attributed, the argument `findMe` is removed from the shared scope. See the `localEnv.info.scope.leave()` at the end of `Attr::visitLambda`. This is why it is necessary to duplicate the scope as proposed in this patch.



PR: https://git.openjdk.java.net/jdk/pull/6977

More information about the compiler-dev mailing list