RFR: 8310133: Effectivelly final condition not enforced in guards for binding variables from the same case
Vicente Romero
vromero at openjdk.org
Tue Jun 20 17:56:04 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.
looks sensible
-------------
Marked as reviewed by vromero (Reviewer).
PR Review: https://git.openjdk.org/jdk/pull/14498#pullrequestreview-1488702242
More information about the compiler-dev
mailing list