Commit f495cf6
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>1 parent aeb5cab commit f495cf6
4 files changed
Lines changed: 22 additions & 14 deletions
File tree
- java
- kotlin-extractor/src/main/kotlin/comments
- ql/test-kotlin1/library-tests
- comments
- dataflow/func
Lines changed: 17 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
95 | 96 | | |
96 | 97 | | |
97 | 98 | | |
98 | | - | |
99 | | - | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
100 | 114 | | |
101 | 115 | | |
102 | 116 | | |
| |||
111 | 125 | | |
112 | 126 | | |
113 | 127 | | |
114 | | - | |
| 128 | + | |
115 | 129 | | |
116 | 130 | | |
117 | 131 | | |
| |||
Lines changed: 4 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
19 | 18 | | |
| 19 | + | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
39 | 38 | | |
40 | 39 | | |
41 | 40 | | |
42 | | - | |
43 | 41 | | |
44 | | - | |
| 42 | + | |
45 | 43 | | |
46 | 44 | | |
47 | 45 | | |
| |||
69 | 67 | | |
70 | 68 | | |
71 | 69 | | |
72 | | - | |
| 70 | + | |
73 | 71 | | |
74 | 72 | | |
75 | 73 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| |||
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
94 | | - | |
95 | | - | |
Lines changed: 0 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | | - | |
35 | | - | |
0 commit comments