Commit Graph

6 Commits

Author SHA1 Message Date
Anders Fugmann
fa5b17aac8 [C15] Kotlin: emit _ for source underscore locals under K2
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>
2026-07-12 18:38:34 +02:00
Owen Mansel-Chan
29b0c286a7 Fix 3 more tests 2026-06-11 23:40:14 +02:00
Owen Mansel-Chan
a375e186ed Third pass 2026-06-11 21:53:22 +02:00
Ian Lynagh
eab32ea24b Kotlin 2: Accept changes in query-tests/UnderscoreIdentifier 2023-12-08 13:49:25 +00:00
Ian Lynagh
7a49d6e9bd K2: query-tests/UselessNullCheck: Accept location changes 2023-11-17 14:07:13 +00:00
Ian Lynagh
905583e00a Kotlin: Add a Kotlin 2 copy of the testsuite 2023-11-17 14:07:13 +00:00