Integrated: 8310326: Incorrect position of the synthetic unnamed class

Jan Lahoda jlahoda at openjdk.org
Tue Jun 20 10:38:11 UTC 2023


On Mon, 19 Jun 2023 19:01:28 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:

> Considering code like:
> 
> void main() {
> }
> 
> 
> The method is wrapped in a synthetic class. But, for, this class:
>  - `SourcePositions.getStartPosition` returns `5`, while `0` would be better (the reason is the the "name"/"preferred" position from the first member is used, not the starting position for the first member)
>  - has (synthetic) empty modifiers with starting position `5`, while normally empty modifiers have starting pos `-1`, e.g.:
> https://github.com/openjdk/jdk/blob/33c6ec9d4eb36649a94125aa005dc6b961dcd2c1/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java#L3525
> 
> This patch proposes to:
>  - use the starting position of the first member as the position of the class
>  - use `-1` as the position for the empty synthetic modifiers of the class
> 
> End positions for neither of these is not set, and continues not to be set, and hence `getEndPosition` returns `-1`. That is (AFAIK) the common behavior for synthetic trees.

This pull request has now been integrated.

Changeset: 4ca548fe
Author:    Jan Lahoda <jlahoda at openjdk.org>
URL:       https://git.openjdk.org/jdk/commit/4ca548fe74419dc9e110489e3d2d3adf695ef37f
Stats:     28 lines in 2 files changed: 25 ins; 0 del; 3 mod

8310326: Incorrect position of the synthetic unnamed class

Reviewed-by: jlaskey

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

PR: https://git.openjdk.org/jdk/pull/14548


More information about the compiler-dev mailing list