Add cached builtin and unignore ScriptTest cached
This commit is contained in:
parent
f9c29e742a
commit
2e9e0921bf
@ -346,6 +346,23 @@ class Script(
|
|||||||
addFn("run") {
|
addFn("run") {
|
||||||
requireOnlyArg<Statement>().execute(this)
|
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") {
|
addVoidFn("delay") {
|
||||||
val a = args.firstAndOnly()
|
val a = args.firstAndOnly()
|
||||||
|
|||||||
@ -3564,7 +3564,6 @@ class ScriptTest {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Ignore("incremental enable")
|
|
||||||
@Test
|
@Test
|
||||||
fun cachedTest() = runTest {
|
fun cachedTest() = runTest {
|
||||||
eval(
|
eval(
|
||||||
@ -3608,14 +3607,12 @@ class ScriptTest {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Ignore("incremental enable: run helper not resolved in new compiler")
|
|
||||||
@Test
|
@Test
|
||||||
fun testElvisAndThrow2() = runTest {
|
fun testElvisAndThrow2() = runTest {
|
||||||
eval(
|
eval(
|
||||||
"""
|
"""
|
||||||
val t = "112"
|
val t = "112"
|
||||||
val x = t ?: run { throw "testx" }
|
val x = t ?: run { throw "testx" }
|
||||||
}
|
|
||||||
assertEquals( "112", x)
|
assertEquals( "112", x)
|
||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
)
|
)
|
||||||
@ -4383,9 +4380,9 @@ class ScriptTest {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Ignore("incremental enable: unresolved names are now compile-time errors")
|
|
||||||
@Test
|
@Test
|
||||||
fun testHangOnNonexistingMethod() = runTest {
|
fun testHangOnNonexistingMethod() = runTest {
|
||||||
|
assertFailsWith<ScriptError> {
|
||||||
eval(
|
eval(
|
||||||
"""
|
"""
|
||||||
class T(someList) {
|
class T(someList) {
|
||||||
@ -4394,18 +4391,13 @@ class ScriptTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
val t = T([1,2])
|
val t = T([1,2])
|
||||||
try {
|
|
||||||
for( i in 1..10 ) {
|
for( i in 1..10 ) {
|
||||||
t.f()
|
t.f()
|
||||||
}
|
}
|
||||||
}
|
""".trimIndent()
|
||||||
catch(t: SymbolNotFound) {
|
|
||||||
println(t::class)
|
|
||||||
// ok
|
|
||||||
}
|
|
||||||
"""
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testUsingClassConstructorVars() = runTest {
|
fun testUsingClassConstructorVars() = runTest {
|
||||||
@ -4537,7 +4529,6 @@ class ScriptTest {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Ignore("incremental enable: cached helper not resolved in new compiler")
|
|
||||||
@Test
|
@Test
|
||||||
fun testCached() = runTest {
|
fun testCached() = runTest {
|
||||||
eval(
|
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
|
@Test
|
||||||
fun realWorldCaptureProblem() = runTest {
|
fun realWorldCaptureProblem() = runTest {
|
||||||
eval(
|
eval(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user