[jdk23] Integrated: 8335817: javac AssertionError addLocalVar checkNull

Jan Lahoda jlahoda at openjdk.org
Thu Jul 18 04:55:37 UTC 2024


On Mon, 15 Jul 2024 15:02:45 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:

> Hi all,
> 
> This pull request contains a backport of commit [2b0adfc2](https://github.com/openjdk/jdk/commit/2b0adfc2decf47f6f49f072549c96f301f275285) from the [openjdk/jdk](https://git.openjdk.org/jdk) repository.
> 
> The commit being backported was authored by Jan Lahoda on 15 Jul 2024 and was reviewed by Vicente Romero and Maurizio Cimadamore.
> 
> Thanks!
> 
> Original description:
> Consider pattern matching with deconstruction patter, like:
> 
> boolean b = o instanceof R(String s);
> 
> 
> This will get desugared into code similar to `o instanceof R r && r.component() instanceof String s`, except that the call to `component()` is guarded with a try-catch, wrapping any exception with a `MatchException`. The internal javac implementation is to create a synthetic catch clause, and attach it to the relevant enclosing block.
> 
> Now, consider an expression lambda with a deconstruction pattern matching, like `o -> o instanceof R(String s)`. There is no block in the lambda to which the catch could be attached. So, `TransPatterns` will expand the expression lambda to a block lambda, and inject the synthetic catches. But, `TransPatterns` will always do `return <expression-body>;`, even if the type of `<expression-body>` is void. This then leads to a crash during Gen, as a variable of type `void` is created.
> 
> The patch proposed here avoid creating `return <expression-body>;` for void-type expression.

This pull request has now been integrated.

Changeset: e83e2b30
Author:    Jan Lahoda <jlahoda at openjdk.org>
URL:       https://git.openjdk.org/jdk/commit/e83e2b305e46d10a82ad30d58adabf676572576b
Stats:     157 lines in 2 files changed: 155 ins; 0 del; 2 mod

8335817: javac AssertionError addLocalVar checkNull

Reviewed-by: mcimadamore
Backport-of: 2b0adfc2decf47f6f49f072549c96f301f275285

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

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


More information about the compiler-dev mailing list