mirror of
https://github.com/github/codeql.git
synced 2026-07-13 23:38:15 +02:00
For `class C : Intf by <expr>` the compiler synthesises a `$$delegate_0` field
that stores the delegate `<expr>`, so its natural location is that expression.
The two frontends disagreed on the field's own location:
- K1 records it at the delegate expression (`intfDelegate.kt:7:26:9:1`, the
`object : Intf { ... }`); while
- K2 records it from the delegated supertype, so it includes the `Intf by `
glue (`7:18:9:1`).
This is the interface-delegation analogue of the delegated-property `$delegate`
field, where we already adopted the delegate-expression span and excluded the
`by` keyword (it is syntactic glue, not part of the stored expression). We apply
the same principle here and converge K2 onto K1's narrower span.
`getClassDelegateFieldLocation` anchors a class-delegation field
(`IrDeclarationOrigin.DELEGATE`, which has no corresponding property and would
otherwise fall through to the raw IR offset) on its own initialiser expression.
It uses the initialiser's raw offsets, which are available under both frontends
(`7:26:9:1` in each), so it is frontend-stable: under K1 it reproduces the offset
already recorded (no change) and under K2 it trims the leading `Intf by `.
Relearn (both suites, CPUS=5): all 3333 tests pass. Only test-kotlin2 changes;
interface-delegate/test is now byte-identical across suites (2 -> 0 divergent
rows). No other file changes.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>