Commit 7ea8558
Kotlin: converge delegated-property accessor synthetic thisRef locations onto K2
For `val x by Delegate()`, the compiler synthesises getter/setter bodies that
forward to the delegate's `getValue`/`setValue`, passing a synthetic receiver
argument (the enclosing `this`, or `null` for top-level/extension delegates).
Under the K1 frontend (test-kotlin1, `-language-version 1.9`) these synthetic
receiver arguments were given a bogus location `1:9:1:12`: their IR offsets
(8..11) are not real source offsets for the argument, and `findPsiElement`
resolves them to whatever sits at file offset 8, which for these tests is the
line-1 `import`. This is meaningless and makes the receivers un-searchable by
location.
The K2 frontend (test-kotlin2, default) already produces the intuitive result:
the synthetic member receiver is located at the DELEGATE EXPRESSION (e.g.
`by ResourceDelegate()` -> `ResourceDelegate()`), and a receiver-less `null`
argument gets the whole-file location `0:0:0:0`. K2 output is the canonical
target for this unification (it is also compiler-version-independent).
This change adds `getDelegatedAccessorSyntheticArgumentLocation`, gated on:
- the enclosing declaration being an IrFunction with origin
DELEGATED_PROPERTY_ACCESSOR (member/top-level accessors only),
- the element being either the accessor's dispatch/extension receiver
`IrGetValue` or a null `CodeQLIrConst`, and
- the element offsets lying outside the enclosing `KtProperty` text range
(so genuine in-source expressions are never rehomed).
It returns the delegate expression's location for the `this`/receiver case and
the whole-file location for the `null` case, mirroring K2. It is wired at the
three sites that extract these synthetic args (extractThisAccess, the
IrGetValue variable/extension-receiver path, and the null case of
extractConstant).
The helper relies on PSI (getPsi2Ir), so it is a no-op under K2: test-kotlin2
output is unchanged (verified). Only test-kotlin1 converges.
Trade-offs / scope:
- LOCAL delegated properties (declared inside a function body) are a distinct
mechanism: their get/set is inlined into the enclosing function (no
DELEGATED_PROPERTY_ACCESSOR origin) and the residual divergence there is an
end-offset difference, not the `1:9:1:12` bug. They are deliberately left
for a separate commit.
- The `$delegate` backing-variable initializer/type-access spans still differ
between suites (e.g. `4:18` vs `4:21`); that is an unrelated mechanism and
is not touched here.
- The outside-KtProperty-range gate could in principle false-negative for a
delegated property declared at the very top of a file (offsets <= 11); this
is preferred to over-correcting real expressions and is not observed in the
test corpus.
Relearned test-kotlin1 expected updated (exprs, methods; incl. PrintAst).
Verified via full dual-suite relearn (CI-faithful: 2.3.20/lang-1.9 for tk1,
default/2.4.0 for tk2, database consistency checks): all 3333 tests pass, only
the three delegates-related tk1 files change, every changed row is a pure
relocation of a synthetic receiver from `1:9:1:12` to the K2 target, and
test-kotlin2 is byte-for-byte unchanged.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent 0de7f77 commit 7ea8558
4 files changed
Lines changed: 108 additions & 42 deletions
File tree
- java
- kotlin-extractor/src/main/kotlin
- ql/test-kotlin1/library-tests
- exprs
- methods
Lines changed: 69 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3123 | 3123 | | |
3124 | 3124 | | |
3125 | 3125 | | |
| 3126 | + | |
| 3127 | + | |
| 3128 | + | |
| 3129 | + | |
| 3130 | + | |
| 3131 | + | |
| 3132 | + | |
| 3133 | + | |
| 3134 | + | |
| 3135 | + | |
| 3136 | + | |
| 3137 | + | |
| 3138 | + | |
| 3139 | + | |
| 3140 | + | |
| 3141 | + | |
| 3142 | + | |
| 3143 | + | |
| 3144 | + | |
| 3145 | + | |
| 3146 | + | |
| 3147 | + | |
| 3148 | + | |
| 3149 | + | |
| 3150 | + | |
| 3151 | + | |
| 3152 | + | |
| 3153 | + | |
| 3154 | + | |
| 3155 | + | |
| 3156 | + | |
| 3157 | + | |
| 3158 | + | |
| 3159 | + | |
| 3160 | + | |
| 3161 | + | |
| 3162 | + | |
| 3163 | + | |
| 3164 | + | |
| 3165 | + | |
| 3166 | + | |
| 3167 | + | |
| 3168 | + | |
| 3169 | + | |
| 3170 | + | |
| 3171 | + | |
| 3172 | + | |
| 3173 | + | |
| 3174 | + | |
| 3175 | + | |
| 3176 | + | |
| 3177 | + | |
| 3178 | + | |
| 3179 | + | |
| 3180 | + | |
| 3181 | + | |
| 3182 | + | |
| 3183 | + | |
| 3184 | + | |
| 3185 | + | |
| 3186 | + | |
| 3187 | + | |
| 3188 | + | |
| 3189 | + | |
3126 | 3190 | | |
3127 | 3191 | | |
3128 | 3192 | | |
| |||
6461 | 6525 | | |
6462 | 6526 | | |
6463 | 6527 | | |
6464 | | - | |
| 6528 | + | |
| 6529 | + | |
6465 | 6530 | | |
6466 | 6531 | | |
6467 | 6532 | | |
| |||
7012 | 7077 | | |
7013 | 7078 | | |
7014 | 7079 | | |
7015 | | - | |
| 7080 | + | |
| 7081 | + | |
7016 | 7082 | | |
7017 | 7083 | | |
7018 | 7084 | | |
| |||
7389 | 7455 | | |
7390 | 7456 | | |
7391 | 7457 | | |
7392 | | - | |
| 7458 | + | |
7393 | 7459 | | |
7394 | 7460 | | |
7395 | 7461 | | |
| |||
Lines changed: 18 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
| 36 | + | |
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| |||
82 | 82 | | |
83 | 83 | | |
84 | 84 | | |
85 | | - | |
| 85 | + | |
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
| |||
644 | 644 | | |
645 | 645 | | |
646 | 646 | | |
647 | | - | |
| 647 | + | |
648 | 648 | | |
649 | 649 | | |
650 | 650 | | |
| |||
687 | 687 | | |
688 | 688 | | |
689 | 689 | | |
690 | | - | |
| 690 | + | |
691 | 691 | | |
692 | 692 | | |
693 | 693 | | |
| |||
891 | 891 | | |
892 | 892 | | |
893 | 893 | | |
894 | | - | |
| 894 | + | |
895 | 895 | | |
896 | 896 | | |
897 | 897 | | |
| |||
936 | 936 | | |
937 | 937 | | |
938 | 938 | | |
939 | | - | |
| 939 | + | |
940 | 940 | | |
941 | 941 | | |
942 | 942 | | |
| |||
1021 | 1021 | | |
1022 | 1022 | | |
1023 | 1023 | | |
1024 | | - | |
| 1024 | + | |
1025 | 1025 | | |
1026 | 1026 | | |
1027 | 1027 | | |
| |||
1067 | 1067 | | |
1068 | 1068 | | |
1069 | 1069 | | |
1070 | | - | |
| 1070 | + | |
1071 | 1071 | | |
1072 | 1072 | | |
1073 | 1073 | | |
| |||
1146 | 1146 | | |
1147 | 1147 | | |
1148 | 1148 | | |
1149 | | - | |
| 1149 | + | |
1150 | 1150 | | |
1151 | 1151 | | |
1152 | 1152 | | |
| |||
1191 | 1191 | | |
1192 | 1192 | | |
1193 | 1193 | | |
1194 | | - | |
| 1194 | + | |
1195 | 1195 | | |
1196 | 1196 | | |
1197 | 1197 | | |
| |||
1278 | 1278 | | |
1279 | 1279 | | |
1280 | 1280 | | |
1281 | | - | |
| 1281 | + | |
1282 | 1282 | | |
1283 | 1283 | | |
1284 | 1284 | | |
| |||
1324 | 1324 | | |
1325 | 1325 | | |
1326 | 1326 | | |
1327 | | - | |
| 1327 | + | |
1328 | 1328 | | |
1329 | 1329 | | |
1330 | 1330 | | |
| |||
1405 | 1405 | | |
1406 | 1406 | | |
1407 | 1407 | | |
1408 | | - | |
| 1408 | + | |
1409 | 1409 | | |
1410 | 1410 | | |
1411 | 1411 | | |
| |||
1471 | 1471 | | |
1472 | 1472 | | |
1473 | 1473 | | |
1474 | | - | |
| 1474 | + | |
1475 | 1475 | | |
1476 | 1476 | | |
1477 | 1477 | | |
| |||
1531 | 1531 | | |
1532 | 1532 | | |
1533 | 1533 | | |
1534 | | - | |
| 1534 | + | |
1535 | 1535 | | |
1536 | 1536 | | |
1537 | 1537 | | |
| |||
1597 | 1597 | | |
1598 | 1598 | | |
1599 | 1599 | | |
1600 | | - | |
| 1600 | + | |
1601 | 1601 | | |
1602 | 1602 | | |
1603 | 1603 | | |
| |||
1642 | 1642 | | |
1643 | 1643 | | |
1644 | 1644 | | |
1645 | | - | |
| 1645 | + | |
1646 | 1646 | | |
1647 | 1647 | | |
1648 | 1648 | | |
| |||
1713 | 1713 | | |
1714 | 1714 | | |
1715 | 1715 | | |
1716 | | - | |
| 1716 | + | |
1717 | 1717 | | |
1718 | 1718 | | |
1719 | 1719 | | |
| |||
0 commit comments