RFR: 8310326: Incorrect position of the synthetic unnamed class

Jan Lahoda jlahoda at openjdk.org
Mon Jun 19 19:08:43 UTC 2023


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.

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

Commit messages:
 - 8310326: Incorrect position of the synthetic unnamed class

Changes: https://git.openjdk.org/jdk/pull/14548/files
 Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=14548&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8310326
  Stats: 28 lines in 2 files changed: 25 ins; 0 del; 3 mod
  Patch: https://git.openjdk.org/jdk/pull/14548.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/14548/head:pull/14548

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


More information about the compiler-dev mailing list