RFR: 8359383: Incorrect starting positions for implicitly typed variables [v2]

Archie Cobbs acobbs at openjdk.org
Sun Aug 31 22:55:44 UTC 2025


On Mon, 11 Aug 2025 18:17:35 GMT, Archie Cobbs <acobbs at openjdk.org> wrote:

>> This fixes starting position bugs relating to implicitly typed variables; see the linked issue for details.
>> 
>> This also makes it possible to recover the declaration type (explicit, implicit, or `var`) from a `JCVariableDecl` and, in the case of `var` declarations, the starting position of the `var`; previously this wasn't possible.
>> 
>> Finally, as a minor drive-by improvement, we can now pretty print `var` as `var` instead of `/*missing*/`.
>
> Archie Cobbs has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains three additional commits since the last revision:
> 
>  - Add back regression test case that got removed somehow.
>  - Merge branch 'master' into JDK-8359383
>  - Fix various starting position bugs relating to implicitly typed variables.

The only change that should be visible is in the case of a `final var` lambda parameter, e.g.:

Consumer<String> c = (final var testVar) -> {};

Before: the `JCVariableDecl` for `testVar` starts at `var`
After: the `JCVariableDecl` for `testVar` starts at `final`

But note that change is just making the lambda case consistent with how all these other cases already behave:

(a) final var testVar = 0;
(b) switch (x) { case Rec(final var testVar) -> {} }
(c) for (final var testVar : List.of(0, 1)) {}

Before: the `JCVariableDecl` for `testVar` starts at `final`
After: the `JCVariableDecl` for `testVar` starts at `final`

So I think this is really just a bug fix rather than a behavioral change.

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

PR Comment: https://git.openjdk.org/jdk/pull/25786#issuecomment-3240469046


More information about the compiler-dev mailing list