Kotlin: include accessor annotations in explicit accessor location

An explicit property accessor may carry its own annotations, for example:

    val x: Int
        @JvmName("getX_prop")
        get() = 15

The K2 frontend records such an accessor with raw IR offsets that begin
at the leading annotation; the K1 frontend's raw offsets start at the
`get`/`set` keyword and omit the annotation. This is a pure K1
information regression: the annotation is part of the accessor
declaration and the K2 span is the more faithful one, so we converge K1
onto K2.

Because the annotation-inclusive start cannot be reconstructed under K2
(no PSI back-mapping) but is trivially available under K1, we recover it
from the KtPropertyAccessor PSI node, whose text range begins at its
modifier list. A new helper getPsiBasedAnnotatedAccessorLocation returns
this span, and accessorOverride now applies it to explicit accessors (in
addition to the existing synthesised-accessor handling).

Guards keep the change surgical:
  - returns null under K2 (getKtFile unavailable; raw offsets already
    include the annotation), leaving K2 untouched.
  - returns null when the accessor declares no annotations of its own, so
    non-annotated explicit accessors (which already converge) are
    unaffected.

Relearned both suites: only explicit annotated-accessor declaration rows
change (K1 now matches K2). annotations/jvmName/test.expected becomes
byte-identical across suites; the residual diffs in jvmstatic-annotation
are pre-existing, unrelated divergences (JVM-static proxy forwarder
locations and call-argument spans).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Anders Fugmann
2026-07-12 16:08:25 +02:00
parent 5626a5d897
commit db88f07a3a
3 changed files with 36 additions and 7 deletions

View File

@@ -1,5 +1,5 @@
| Test.java:2:17:2:17 | m | m | m |
| test.kt:4:9:4:18 | getX_prop | getX_prop | getX |
| test.kt:3:9:4:18 | getX_prop | getX_prop | getX |
| test.kt:6:5:6:19 | getX | getX | getX |
| test.kt:10:5:10:14 | changeY | changeY | setY |
| test.kt:10:5:10:14 | y | y | getY |

View File

@@ -12,8 +12,8 @@ staticMembers
| test.kt:31:1:47:1 | NonCompanion | test.kt:33:14:33:69 | staticMethod | Method |
| test.kt:31:1:47:1 | NonCompanion | test.kt:36:14:36:35 | getStaticProp | Method |
| test.kt:31:1:47:1 | NonCompanion | test.kt:36:14:36:35 | setStaticProp | Method |
| test.kt:31:1:47:1 | NonCompanion | test.kt:40:16:40:43 | getPropWithStaticGetter | Method |
| test.kt:31:1:47:1 | NonCompanion | test.kt:45:16:45:58 | setPropWithStaticSetter | Method |
| test.kt:31:1:47:1 | NonCompanion | test.kt:40:5:40:43 | getPropWithStaticGetter | Method |
| test.kt:31:1:47:1 | NonCompanion | test.kt:45:5:45:58 | setPropWithStaticSetter | Method |
#select
| test.kt:9:1:29:1 | HasCompanion | JavaUser.java:5:5:5:34 | staticMethod(...) | JavaUser.java:5:5:5:16 | HasCompanion | static |
| test.kt:9:1:29:1 | HasCompanion | JavaUser.java:7:5:7:73 | setStaticProp(...) | JavaUser.java:7:5:7:16 | HasCompanion | static |