Skip to content

Commit 701a005

Browse files
Kotlin: assign stable context parameter indices
Derive Kotlin 2.4 parameter indices from preceding context and regular parameters while reserving the Java parameter slot for an extension receiver. This removes negative context-parameter indices and prevents setter parameter label collisions found by the consistency checks. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent aa583f8 commit 701a005

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

java/kotlin-extractor/src/main/kotlin/utils/versions/v_2_4_0/parameterIndexExcludingReceivers.kt

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,15 @@ import org.jetbrains.kotlin.ir.declarations.IrParameterKind
55
import org.jetbrains.kotlin.ir.declarations.IrValueParameter
66

77
fun parameterIndexExcludingReceivers(vp: IrValueParameter): Int {
8-
val offset =
9-
(vp.parent as? IrFunction)?.let { f ->
10-
f.parameters.count { it.kind == IrParameterKind.DispatchReceiver || it.kind == IrParameterKind.ExtensionReceiver || it.kind == IrParameterKind.Context }
11-
} ?: 0
12-
return vp.indexInParameters - offset
8+
if (
9+
vp.kind == IrParameterKind.DispatchReceiver ||
10+
vp.kind == IrParameterKind.ExtensionReceiver
11+
) {
12+
return -1
13+
}
14+
return (vp.parent as? IrFunction)
15+
?.parameters
16+
?.take(vp.indexInParameters)
17+
?.count { it.kind == IrParameterKind.Context || it.kind == IrParameterKind.Regular }
18+
?: vp.indexInParameters
1319
}

0 commit comments

Comments
 (0)