Skip to content

Commit edaa710

Browse files
Kotlin: converge explicit _ setter parameter name onto K2
An explicit property setter written `set(_)` produces a value parameter whose source spelling is the Kotlin discard placeholder `_`. The two frontends model this differently: * K2 preserves the source name and exposes the parameter as `_`. * K1 additionally flags the parameter with `IrDeclarationOrigin.UNDERSCORE_PARAMETER`, which the extractor treats as a synthesized name (no name is written and QL synthesizes `p0`). This made `test-kotlin1` report `p0` while `test-kotlin2` reported `_` for the same source (library-tests/underscore-parameters). The `UNDERSCORE_PARAMETER` origin is *also* set by K1 (and, for the synthesized cases, by K2) on discarded parameters that do not retain a `_` source spelling, most importantly: * lambda placeholder parameters, e.g. `{ index, _ -> ... }` * the synthesized `invoke` parameters of function types (funcExprs.kt lines 27/30/31/90/94) For those, the two frontends assign *different* internal names (`<anonymous parameter N>` under K1 vs `<unused var>` under K2), so the synthetic-name treatment is exactly what keeps them converged at `pN`. Removing the origin check wholesale therefore replaces one small divergence with a much larger one. To converge only the case both frontends agree on, we suppress the synthetic-name treatment only when the parameter's own name is exactly `_` (the source discard spelling that both K1 and K2 preserve). This makes K1 emit `_` for `set(_)` (matching K2) while leaving every other discarded parameter synthetic in both suites. Scope of the change (verified by a full dual-suite `--learn` with database-consistency checks, all 3333 tests passing): * test-kotlin1 library-tests/underscore-parameters: `p0` -> `_` (now identical to test-kotlin2). * test-kotlin2: byte-for-byte unchanged. * No other expected file changes (lambda / function-type discard parameters remain `pN` in both suites). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent a376228 commit edaa710

2 files changed

Lines changed: 3 additions & 2 deletions

File tree

java/kotlin-extractor/src/main/kotlin/KotlinFileExtractor.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1365,7 +1365,8 @@ open class KotlinFileExtractor(
13651365
extractTypeAccessRecursive(substitutedType, location, id, -1)
13661366
}
13671367
val syntheticParameterNames =
1368-
vp.origin == IrDeclarationOrigin.UNDERSCORE_PARAMETER ||
1368+
(vp.origin == IrDeclarationOrigin.UNDERSCORE_PARAMETER &&
1369+
vp.name.asString() != "_") ||
13691370
((vp.parent as? IrFunction)?.let { hasSynthesizedParameterNames(it) } ?: true)
13701371
val javaParameter =
13711372
when (val callable = (vp.parent as? IrFunction)?.let { getJavaCallable(it) }) {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
| test.kt:5:9:5:9 | p0 | p0 |
1+
| test.kt:5:9:5:9 | _ | _ |

0 commit comments

Comments
 (0)