Commit 915d4d4
Kotlin: exclude the
For a delegated property `var x: Int by ResourceDelegate()` the two
frontend paths anchor the synthesised delegate locations differently:
- K1 (-language-version 1.9) starts them at the `by` keyword.
- K2 (default) starts them at the delegate expression itself
(e.g. `ResourceDelegate()`), three columns later (`by ` excluded).
The `by` keyword is syntactic glue joining the property to its delegate,
not part of the expression that is evaluated and stored, so K2's narrower
range is the more intuitive one. An existing remap already converged the
delegated-accessor *body* expressions onto the K2 span; this commit
converges the two remaining sites.
1. The `$delegate` backing field. `getDelegateFieldLocation` recovers the
delegate expression's range from the enclosing `KtProperty` via PSI
(available under K1; null under K2, where the raw offsets already
exclude `by`) and is used both for the field's declaration location
(extractField) and for its initializer assignment / lhs access
(extractFieldInitializer's declLocId). It fires only for a delegated
property's own backing field (`isDelegated` and `backingField === f`).
2. Local delegated properties. The `provideDelegate(...)` call and its
`KProperty` argument in the delegate variable's initializer span the
whole `by <expr>` range under K1; the `IrLocalDelegatedProperty`
branch now applies the same `scopedOffsetRemap` used for accessor
bodies while extracting that variable.
The shared PSI walk is factored into `getEnclosingKtProperty` and a
`KtProperty`-keyed `getDelegateExpressionOffsetRemap` overload.
Result: test-kotlin1 and test-kotlin2 exprs/delegatedProperties.expected
and exprs/funcExprs.expected are now byte-identical. exprs/exprs.expected
and methods/exprs.expected have their delegate rows converged (remaining
diffs in those two files are unrelated mechanisms: implicit-cast nodes and
the property-type / setter-parameter spans, addressed separately). All
3333 tests pass in both suites (K1 2.3.20 / lang 1.9 and K2 2.4.0 /
lang 2.0).
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>by keyword from delegated-property locations1 parent 5dc4830 commit 915d4d4
5 files changed
Lines changed: 138 additions & 84 deletions
File tree
- java
- kotlin-extractor/src/main/kotlin
- ql/test-kotlin1/library-tests
- exprs
- methods
Lines changed: 59 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1610 | 1610 | | |
1611 | 1611 | | |
1612 | 1612 | | |
1613 | | - | |
| 1613 | + | |
1614 | 1614 | | |
1615 | 1615 | | |
1616 | 1616 | | |
| |||
2677 | 2677 | | |
2678 | 2678 | | |
2679 | 2679 | | |
| 2680 | + | |
2680 | 2681 | | |
2681 | 2682 | | |
2682 | 2683 | | |
| |||
3454 | 3455 | | |
3455 | 3456 | | |
3456 | 3457 | | |
| 3458 | + | |
| 3459 | + | |
| 3460 | + | |
| 3461 | + | |
| 3462 | + | |
| 3463 | + | |
| 3464 | + | |
| 3465 | + | |
| 3466 | + | |
3457 | 3467 | | |
3458 | | - | |
3459 | | - | |
| 3468 | + | |
| 3469 | + | |
3460 | 3470 | | |
3461 | | - | |
| 3471 | + | |
| 3472 | + | |
| 3473 | + | |
| 3474 | + | |
| 3475 | + | |
| 3476 | + | |
| 3477 | + | |
| 3478 | + | |
| 3479 | + | |
| 3480 | + | |
| 3481 | + | |
3462 | 3482 | | |
3463 | 3483 | | |
3464 | 3484 | | |
| |||
3467 | 3487 | | |
3468 | 3488 | | |
3469 | 3489 | | |
| 3490 | + | |
| 3491 | + | |
| 3492 | + | |
| 3493 | + | |
| 3494 | + | |
| 3495 | + | |
| 3496 | + | |
| 3497 | + | |
| 3498 | + | |
| 3499 | + | |
| 3500 | + | |
| 3501 | + | |
| 3502 | + | |
| 3503 | + | |
| 3504 | + | |
| 3505 | + | |
| 3506 | + | |
| 3507 | + | |
| 3508 | + | |
| 3509 | + | |
| 3510 | + | |
| 3511 | + | |
3470 | 3512 | | |
3471 | 3513 | | |
3472 | 3514 | | |
| |||
3673 | 3715 | | |
3674 | 3716 | | |
3675 | 3717 | | |
3676 | | - | |
| 3718 | + | |
| 3719 | + | |
| 3720 | + | |
| 3721 | + | |
| 3722 | + | |
| 3723 | + | |
| 3724 | + | |
| 3725 | + | |
| 3726 | + | |
| 3727 | + | |
| 3728 | + | |
| 3729 | + | |
| 3730 | + | |
3677 | 3731 | | |
3678 | 3732 | | |
3679 | 3733 | | |
| |||
Lines changed: 12 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| |||
0 commit comments