Add cached builtin and unignore ScriptTest cached
This commit is contained in:
parent
f9c29e742a
commit
2e9e0921bf
@ -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()
|
||||
|
||||
@ -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,9 +4380,9 @@ class ScriptTest {
|
||||
)
|
||||
}
|
||||
|
||||
@Ignore("incremental enable: unresolved names are now compile-time errors")
|
||||
@Test
|
||||
fun testHangOnNonexistingMethod() = runTest {
|
||||
assertFailsWith<ScriptError> {
|
||||
eval(
|
||||
"""
|
||||
class T(someList) {
|
||||
@ -4394,18 +4391,13 @@ class ScriptTest {
|
||||
}
|
||||
}
|
||||
val t = T([1,2])
|
||||
try {
|
||||
for( i in 1..10 ) {
|
||||
t.f()
|
||||
}
|
||||
}
|
||||
catch(t: SymbolNotFound) {
|
||||
println(t::class)
|
||||
// ok
|
||||
}
|
||||
"""
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testUsingClassConstructorVars() = runTest {
|
||||
@ -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(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user