Integrated: 8310133: Effectivelly final condition not enforced in guards for binding variables from the same case
Jan Lahoda
jlahoda at openjdk.org
Wed Jun 21 09:19:15 UTC 2023
On Thu, 15 Jun 2023 16:21:59 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:
> Consider code containing snippet like:
>
> ...
> case String s when s.isEmpty() -> {
> s = null;
> }
> ...
>
>
> The `s` binding variable is obviously not effectively final, but the specification currently requires variables used inside the guard to be effectively final or final.
>
> The cause here is in a position check - for error reporting we need to sent a shared variable `currentTree` to the case, but the effectively final check will only check variables declared before the start of `currentTree` (to avoid reporting issues for variables inside a lambda, for example). The proposed fix is to keep the case inside `currentTree`, but ensure the guard's starting position is used, to allow a proper effectively final check.
This pull request has now been integrated.
Changeset: 01623f6a
Author: Jan Lahoda <jlahoda at openjdk.org>
URL: https://git.openjdk.org/jdk/commit/01623f6a5724d3eb250c48656be0aaf28df11750
Stats: 13 lines in 3 files changed: 9 ins; 0 del; 4 mod
8310133: Effectivelly final condition not enforced in guards for binding variables from the same case
Reviewed-by: vromero
-------------
PR: https://git.openjdk.org/jdk/pull/14498
More information about the compiler-dev
mailing list