Integrated: 8302865: Illegal bytecode for break from if with instanceof pattern matching condition

Jan Lahoda jlahoda at openjdk.org
Wed Jun 21 09:19:15 UTC 2023


On Fri, 16 Jun 2023 11:52:08 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:

> Please see the CSR for the exact wording of the specification change:
> https://bugs.openjdk.org/browse/JDK-8310016
> 
> There are two changes to flow scoping under this PR:
> 
> a) for code like:
> 
> 
> X: if (!(o instanceof String s)) {
>     break X;
> }
> System.err.println(s);
> 
> 
> `s` won't be in the scope for `System.err.println` anymore (as that leads to an invalid bytecode anyway). I was experimenting with several possibilities to fix this, and the final proposal is (when we are about to add some bindings to the scope), look for an immediately enclosing labelled statement(s), and there's some, look for a break to this statement(s).
> 
> b) for code like:
> 
> 
> X: {
>          while (!(o instanceof String s)) {
>              break X;
>          }
>          System.err.println(s);
> }
> 
> 
> javac implements a strict interpretation of the specification, which does not include `s` in the scope for the `System.err.println` (due to the `break` out of the `while`). The specification is clarified, so that only breaks to the loop are considered (together with breaks to the enclosing labelled statements), so flow scoping handling for loops is adjusted to only consider breaks to the loop.

This pull request has now been integrated.

Changeset: a15db1a5
Author:    Jan Lahoda <jlahoda at openjdk.org>
URL:       https://git.openjdk.org/jdk/commit/a15db1a56c560406eac0ac60c29a0ffd15984267
Stats:     244 lines in 6 files changed: 176 ins; 49 del; 19 mod

8302865: Illegal bytecode for break from if with instanceof pattern matching condition

Reviewed-by: vromero

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

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


More information about the compiler-dev mailing list