[jdk17] Integrated: 8269354: javac crashes when processing parenthesized pattern in instanceof
Jan Lahoda
jlahoda at openjdk.java.net
Thu Jul 1 10:13:01 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.
This pull request has now been integrated.
Changeset: a8385feb
Author: Jan Lahoda <jlahoda at openjdk.org>
URL: https://git.openjdk.java.net/jdk17/commit/a8385feb30bd7bd59bcc808de046fcd2e4fb92c1
Stats: 14 lines in 2 files changed: 7 ins; 0 del; 7 mod
8269354: javac crashes when processing parenthesized pattern in instanceof
Reviewed-by: vromero
-------------
PR: https://git.openjdk.java.net/jdk17/pull/147
More information about the compiler-dev
mailing list