RFR: 8279290: symbol not found error, implicit lambdas and diamond constructor invocations
Vicente Romero
vromero at openjdk.java.net
Thu Jan 6 05:57:41 UTC 2022
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.
TIA
-------------
Commit messages:
- 8279290: symbol not found error, implicit lambdas and diamond constructor invocations
Changes: https://git.openjdk.java.net/jdk/pull/6977/files
Webrev: https://webrevs.openjdk.java.net/?repo=jdk&pr=6977&range=00
Issue: https://bugs.openjdk.java.net/browse/JDK-8279290
Stats: 56 lines in 2 files changed: 55 ins; 0 del; 1 mod
Patch: https://git.openjdk.java.net/jdk/pull/6977.diff
Fetch: git fetch https://git.openjdk.java.net/jdk pull/6977/head:pull/6977
PR: https://git.openjdk.java.net/jdk/pull/6977
More information about the compiler-dev
mailing list