diff --git a/lynglib/src/commonMain/kotlin/net/sergeych/lyng/Compiler.kt b/lynglib/src/commonMain/kotlin/net/sergeych/lyng/Compiler.kt index b1163e6..d7c860f 100644 --- a/lynglib/src/commonMain/kotlin/net/sergeych/lyng/Compiler.kt +++ b/lynglib/src/commonMain/kotlin/net/sergeych/lyng/Compiler.kt @@ -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") } diff --git a/lynglib/src/commonTest/kotlin/ScriptTest.kt b/lynglib/src/commonTest/kotlin/ScriptTest.kt index 1ea2ebb..e2e0159 100644 --- a/lynglib/src/commonTest/kotlin/ScriptTest.kt +++ b/lynglib/src/commonTest/kotlin/ScriptTest.kt @@ -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()) + } }