RFR: 8310326: Incorrect position of the synthetic unnamed class

Jim Laskey jlaskey at openjdk.org
Mon Jun 19 19:43:02 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.

LGTM

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

Marked as reviewed by jlaskey (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/14548#pullrequestreview-1486827167


More information about the compiler-dev mailing list