Add cached builtin and unignore ScriptTest cached

This commit is contained in:
Sergey Chernov 2026-01-30 20:33:11 +03:00
parent f9c29e742a
commit 2e9e0921bf
2 changed files with 30 additions and 22 deletions

View File

@ -346,6 +346,23 @@ class Script(
addFn("run") {
requireOnlyArg<Statement>().execute(this)
}
addFn("cached") {
val builder = requireOnlyArg<Statement>()
val capturedScope = this
var calculated = false
var cachedValue: Obj = ObjVoid
val thunk = object : Statement() {
override val pos: Pos = Pos.builtIn
override suspend fun execute(scope: Scope): Obj {
if (!calculated) {
cachedValue = builder.execute(capturedScope)
calculated = true
}
return cachedValue
}
}
thunk
}
addVoidFn("delay") {
val a = args.firstAndOnly()

View File

@ -3564,7 +3564,6 @@ class ScriptTest {
)
}
@Ignore("incremental enable")
@Test
fun cachedTest() = runTest {
eval(
@ -3608,14 +3607,12 @@ class ScriptTest {
)
}
@Ignore("incremental enable: run helper not resolved in new compiler")
@Test
fun testElvisAndThrow2() = runTest {
eval(
"""
val t = "112"
val x = t ?: run { throw "testx" }
}
assertEquals( "112", x)
""".trimIndent()
)
@ -4383,28 +4380,23 @@ class ScriptTest {
)
}
@Ignore("incremental enable: unresolved names are now compile-time errors")
@Test
fun testHangOnNonexistingMethod() = runTest {
eval(
"""
class T(someList) {
fun f() {
nonExistingMethod()
assertFailsWith<ScriptError> {
eval(
"""
class T(someList) {
fun f() {
nonExistingMethod()
}
}
}
val t = T([1,2])
try {
for( i in 1..10 ) {
val t = T([1,2])
for( i in 1..10 ) {
t.f()
}
}
catch(t: SymbolNotFound) {
println(t::class)
// ok
}
"""
)
""".trimIndent()
)
}
}
@Test
@ -4537,7 +4529,6 @@ class ScriptTest {
)
}
@Ignore("incremental enable: cached helper not resolved in new compiler")
@Test
fun testCached() = runTest {
eval(
@ -4935,7 +4926,7 @@ class ScriptTest {
)
}
@Ignore("incremental enable: run helper not resolved in new compiler")
@Ignore("incremental enable: capture of static var inside run block not resolved")
@Test
fun realWorldCaptureProblem() = runTest {
eval(