RFR: 8335817: javac AssertionError addLocalVar checkNull

Vicente Romero vromero at openjdk.org
Thu Jul 11 10:20:55 UTC 2024


On Wed, 10 Jul 2024 12:16:58 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:

> 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.

lgtm

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

Marked as reviewed by vromero (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/20110#pullrequestreview-2171502704


More information about the compiler-dev mailing list