[jdk17] RFR: 8269354: javac crashes when processing parenthesized pattern in instanceof
Vicente Romero
vromero at openjdk.java.net
Tue Jun 29 21:31:05 UTC 2021
On Fri, 25 Jun 2021 14:37:53 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:
> When having code like:
>
> if (o instanceof String s) {
> System.err.println(s);
> }
>
>
> `javac` needs to hoist the `s` binding variable out of the `if` statement. This is done through `BindingContext` in `TransPatterns`. Sometimes, there is no statement out of which the variable would need to be hoisted, like:
>
> boolean b = o instanceof String s && !s.isEmpty();
>
>
> so some expressions (`&&` in the example) also serve as a place where the binding variables can be hoisted. With the addition of parenthesized and guarded patterns, the `instanceof` expression needs to be one of such expressions so that in expressions like:
>
> boolean b = o instanceof (String s && !s.isEmpty());
>
>
> the `s.isEmpty()` uses the correct translated/hoisted variable.
lgtm
-------------
Marked as reviewed by vromero (Reviewer).
PR: https://git.openjdk.java.net/jdk17/pull/147
More information about the compiler-dev
mailing list