fixed inline map splats expansion in function calls

This commit is contained in:
Sergey Chernov 2025-12-21 21:12:06 +01:00
parent f6d51e9b94
commit 3dfe98a93d
2 changed files with 15 additions and 2 deletions

View File

@ -1044,7 +1044,7 @@ class Compiler(
}
Token.Type.ELLIPSIS -> {
parseStatement()?.let { args += ParsedArgument(it, t.pos, isSplat = true) }
parseExpression()?.let { args += ParsedArgument(it, t.pos, isSplat = true) }
?: throw ScriptError(t.pos, "Expecting arguments list")
}
@ -1110,7 +1110,7 @@ class Compiler(
}
Token.Type.ELLIPSIS -> {
parseStatement()?.let { args += ParsedArgument(it, t.pos, isSplat = true) }
parseExpression()?.let { args += ParsedArgument(it, t.pos, isSplat = true) }
?: throw ScriptError(t.pos, "Expecting arguments list")
}

View File

@ -4284,4 +4284,17 @@ class ScriptTest {
""".trimIndent())
}
@Test
fun testAutoSplatArgs() = runTest {
eval("""
fun tf(x, y, z) {
"x=%s, y=%s, z=%s"(x,y,z)
}
assertEquals(tf(1, 2, 3), "x=1, y=2, z=3")
val a = { x: 3, y: 4, z: 5 }
assertEquals(tf(...a), "x=3, y=4, z=5")
assertEquals(tf(...{ x: 3, y: 4, z: 50 }), "x=3, y=4, z=50")
""".trimIndent())
}
}