Commit fa5b17a
[C15] Kotlin: emit
A source underscore variable (an unused `_` in a `catch (_: E)` clause or a
`val _ = ...` discard) is named differently by the two frontends:
- K1 keeps the source spelling `_`.
- K2 assigns the synthetic `SpecialNames.UNDERSCORE_FOR_UNUSED_VAR`, which
renders as `<unused var>`.
Decision (D15): adopt the K1 behaviour. `_` is the actual source token, so it
is the more intuitive and source-faithful name; it also keeps the local
variable name consistent with the corresponding value-parameter case, where a
prior fix already normalises the underscore setter parameter to `_`.
`extractVariableExpr` now maps a variable whose IR name is
`SpecialNames.UNDERSCORE_FOR_UNUSED_VAR` to `_` before writing `localvars`.
The check is on the special name rather than a raw string so it is robust
across compiler versions, and it only fires for the frontend-synthesised
unused-variable name, leaving all other locals untouched.
Full dual-suite relearn: all 3333 tests pass. The only changed expected row is
in query-tests/UnderscoreIdentifier, where the K2 catch parameter row converges
from `Exception <unused var>` to `Exception _`, matching K1. The remaining
divergence in that file (the destructuring container `<destruct>` vs
`tmp0_container`) is a separate naming/location issue tracked under C14.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>_ for source underscore locals under K21 parent 2121d74 commit fa5b17a
2 files changed
Lines changed: 9 additions & 2 deletions
File tree
- java
- kotlin-extractor/src/main/kotlin
- ql/test-kotlin2/query-tests/UnderscoreIdentifier
Lines changed: 8 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
| 54 | + | |
54 | 55 | | |
55 | 56 | | |
56 | 57 | | |
| |||
3489 | 3490 | | |
3490 | 3491 | | |
3491 | 3492 | | |
3492 | | - | |
| 3493 | + | |
| 3494 | + | |
| 3495 | + | |
| 3496 | + | |
| 3497 | + | |
| 3498 | + | |
| 3499 | + | |
3493 | 3500 | | |
3494 | 3501 | | |
3495 | 3502 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
0 commit comments