Commit 8267d33
Kotlin: converge default-accessor body spans onto the K2 signature span
A compiler-generated default property accessor (`DEFAULT_PROPERTY_ACCESSOR`)
has no source body, so the two frontends anchor its synthesised body
expressions (`field = value` / `return field`, plus their `<set-?>`, field and
`this` sub-accesses) differently:
- K1 anchors them at the whole `KtProperty`, whose end offset runs through the
initialiser (`var topLevelInt: Int = 0` -> `60:1:60:24`,
`var curValue = 0` -> `26:13:26:24` .. `26:28`).
- K2 has no PSI for these accessors and falls back to the raw signature span,
which stops at the type (`60:1:60:20`) or, when the type is inferred, at the
name (`26:13:26:24`).
The initialiser is not part of the accessor body (it runs in the field
initialiser / `<clinit>`, not in the setter), so K2's narrower signature span is
the more intuitive, information-preserving choice: it keeps the accessor's
synthetic expressions on the property signature and leaves the initialiser to
the genuine `KtInitializerAssignExpr` / `<clinit>` rows.
We converge K1 onto the K2 span with a scoped offset remap set only while
extracting the accessor body (mirroring the existing delegated-property-accessor
remap). The remap is keyed off the accessor's corresponding property and matches
the property's full IR range exactly, so:
- it only rewrites the synthetic body expressions that carry that range;
- the real field-initialiser rows (which share the same source text but are
extracted in the initialiser context) are untouched and keep their
initialiser-inclusive spans; and
- it is a no-op under K2 (no PSI, so `getEnclosingKtProperty` returns null) and
for any property without an initialiser past its signature.
Tradeoff: this converges K1 onto a span that K2 produces natively but that K1
cannot recover without the PSI, so the direction is fixed (K1 -> K2) rather than
chosen freely. That is acceptable here because the K2 span is the more correct
one on the merits (the initialiser does not belong to the accessor body).
Expected updates (K1 only; K2 already emitted these):
- library-tests/exprs/exprs.expected (setCurValue, setTopLevelInt)
- library-tests/methods/exprs.expected (clinit.kt setTopLevelInt)
Both suites relearned; all tests pass. Divergence 820 -> 798 rows.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 86bfc022-3ecc-4746-ba23-3b76c4e4c3e41 parent fe38154 commit 8267d33
3 files changed
Lines changed: 53 additions & 14 deletions
File tree
- java
- kotlin-extractor/src/main/kotlin
- ql/test-kotlin1/library-tests
- exprs
- methods
Lines changed: 42 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2580 | 2580 | | |
2581 | 2581 | | |
2582 | 2582 | | |
2583 | | - | |
2584 | | - | |
2585 | | - | |
| 2583 | + | |
| 2584 | + | |
| 2585 | + | |
| 2586 | + | |
| 2587 | + | |
| 2588 | + | |
| 2589 | + | |
2586 | 2590 | | |
2587 | 2591 | | |
2588 | 2592 | | |
| |||
3581 | 3585 | | |
3582 | 3586 | | |
3583 | 3587 | | |
| 3588 | + | |
| 3589 | + | |
| 3590 | + | |
| 3591 | + | |
| 3592 | + | |
| 3593 | + | |
| 3594 | + | |
| 3595 | + | |
| 3596 | + | |
| 3597 | + | |
| 3598 | + | |
| 3599 | + | |
| 3600 | + | |
| 3601 | + | |
| 3602 | + | |
| 3603 | + | |
| 3604 | + | |
| 3605 | + | |
| 3606 | + | |
| 3607 | + | |
| 3608 | + | |
| 3609 | + | |
| 3610 | + | |
| 3611 | + | |
| 3612 | + | |
| 3613 | + | |
| 3614 | + | |
| 3615 | + | |
| 3616 | + | |
| 3617 | + | |
| 3618 | + | |
| 3619 | + | |
| 3620 | + | |
| 3621 | + | |
| 3622 | + | |
3584 | 3623 | | |
3585 | 3624 | | |
3586 | 3625 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
116 | 116 | | |
117 | 117 | | |
118 | 118 | | |
| 119 | + | |
| 120 | + | |
119 | 121 | | |
120 | 122 | | |
121 | 123 | | |
122 | 124 | | |
123 | 125 | | |
124 | 126 | | |
| 127 | + | |
125 | 128 | | |
126 | | - | |
127 | | - | |
128 | 129 | | |
129 | 130 | | |
130 | | - | |
131 | 131 | | |
132 | 132 | | |
133 | 133 | | |
| |||
281 | 281 | | |
282 | 282 | | |
283 | 283 | | |
| 284 | + | |
| 285 | + | |
284 | 286 | | |
| 287 | + | |
285 | 288 | | |
| 289 | + | |
286 | 290 | | |
287 | 291 | | |
288 | 292 | | |
289 | 293 | | |
290 | | - | |
291 | | - | |
292 | 294 | | |
293 | | - | |
294 | 295 | | |
295 | | - | |
296 | 296 | | |
297 | 297 | | |
298 | 298 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
1 | 3 | | |
| 4 | + | |
| 5 | + | |
2 | 6 | | |
3 | 7 | | |
4 | 8 | | |
5 | 9 | | |
6 | | - | |
7 | 10 | | |
8 | | - | |
9 | 11 | | |
10 | | - | |
11 | | - | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
0 commit comments