fixed bug with callable argument in calls, added more docs

This commit is contained in:
sergeych committed 2025-06-02 18:33:45 +04:00
1 parent 4a597886e6
commit 29c643eed2
3 files changed
+26 -3

No files matched your search

@@ -499,7 +499,7 @@ class Compiler(
else -> {
cc.previous()
parseStatement(cc)?.let { args += ParsedArgument(it, t.pos) }
parseExpression(cc)?.let { args += ParsedArgument(it, t.pos) }
?: throw ScriptError(t.pos, "Expecting arguments list")
}
}
+17 -2
View File
@@ -1138,7 +1138,8 @@ class ScriptTest {
@Test
fun testIsPrimeSampleBug() = runTest {
eval("""
eval(
"""
fun naive_is_prime(candidate) {
val x = if( candidate !is Int) candidate.toInt() else candidate
var divisor = 1
@@ -1151,6 +1152,20 @@ class ScriptTest {
}
naive_is_prime(4)
""".trimIndent())
""".trimIndent()
)
}
@Test
fun testLambdaAsFnCallArg() = runTest {
eval(
"""
fun mapValues(iterable, transform) {
var result = []
for( x in iterable ) result += transform(x)
}
assert( [11, 21, 31] == mapValues( if( true) [1,2,3] else [10], { it*10+1 }))
""".trimIndent()
)
}
}