Integrated: 8312229: Crash involving yield, switch and anonymous classes
Jan Lahoda
jlahoda at openjdk.org
Wed Jul 26 09:47:59 UTC 2023
On Wed, 19 Jul 2023 10:44:22 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:
> Consider code like:
>
> void test(Object o) {
> Runnable r = () -> {
> switch (o) {
> default -> {
> Integer i = 42;
> new Runnable() {
> public void run() {
> i.toString();
> }
> };
> }
> };
> };
> }
>
>
> During `LambdaToMethod`, the `i` variable is seen as a local variable in the lambda, and re-written to a different variable inside the new lambda method. This is due to:
> https://github.com/openjdk/jdk/blob/d33e8e6f93d7b0806e1d0087c3c0a11fe1bc8e21/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java#L1573
>
> note the lambda frame is the topmost frame in this case.
>
> But, if the code is altered to:
>
> void test(Object o) {
> Runnable r = () -> {
> var l = switch (o) {
> default -> {
> Integer i = 42;
> yield new Runnable() {
> public void run() {
> i.toString();
> }
> };
> }
> };
> };
> }
>
>
> the topmost frame will not be the lambda frame, but rather a variable frame, so that the `i` variable is not seem as a lambda-local variable, and the translations eventually fail.
>
> The proposed solution is to search for the lambda frame, ignoring intervening variable frames.
This pull request has now been integrated.
Changeset: 1f81e5b1
Author: Jan Lahoda <jlahoda at openjdk.org>
URL: https://git.openjdk.org/jdk/commit/1f81e5b19ebfb7cd1b5a01d6cf79efda7e827c35
Stats: 53 lines in 2 files changed: 51 ins; 0 del; 2 mod
8312229: Crash involving yield, switch and anonymous classes
Reviewed-by: vromero
-------------
PR: https://git.openjdk.org/jdk/pull/14930
More information about the compiler-dev
mailing list