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

Vicente Romero vromero at openjdk.org
Fri Jun 16 16:39:57 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.

looks sensible

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

Marked as reviewed by vromero (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/14517#pullrequestreview-1483926857


More information about the compiler-dev mailing list