Files
codeql/java
Anders Fugmann f495cf6fb4 Kotlin: attribute file-level KDoc to the compilation unit (K1/PSI)
A KDoc written before a file's `package` directive documents the file
itself and has no declaration owner: the PSI extractor's `comment.owner`
is null for it. The extractor previously emitted a "Couldn't get owner of
KDoc" diagnostic and recorded no owner in that case. The K2/FIR extractor,
by contrast, already attributes such a comment to the compilation unit,
because the KDOC node is a direct child of the FILE node in the FIR
lighter AST and the enclosing `IrFile` is discovered as its owner. The two
frontends therefore disagreed on file-level KDoc ownership.

Align the PSI extractor with the FIR one: when a KDoc has no declaration
owner but is a direct child of the `KtFile`, attribute it to the file
(`getLabel(file)` yields the compilation-unit label, the same target the
FIR extractor reaches). The now-spurious "Couldn't get owner" diagnostic
is suppressed for file-level KDoc (it remains for any genuinely ownerless
KDoc elsewhere).

This removes the last owner-attribution divergence for file-level KDoc.
The `comments` and `dataflow/func` test sources, which previously carried
frontend-specific text and a `// Diagnostic Matches` line asserting the
old warning, are unified with their K2 counterparts; the K1 expectations
lose the diagnostic and gain the compilation-unit owner row, matching K2.

Remaining `comments` divergence (owners of enum entries, init blocks and
an anonymous function) stems from those IR nodes carrying no FIR source
metadata under K2 and is addressed separately.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-07-14 03:28:21 +02:00
..