Prevent cross-script module slot aliasing
This commit is contained in:
1 parent
ee634c8dff
commit
c80900c503
3 files changed
+58
-9
No files matched your search
@@ -150,6 +150,37 @@ class CompilerVmReviewRegressionTest {
|
||||
assertEquals(42, callable.call(scope, ObjInt.of(40)).toInt())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun preparedLambdaKeepsImmutableModuleCaptureAcrossOtherScriptsInSameScope() = runTest {
|
||||
val unaryLambda = Compiler.compile(
|
||||
Source(
|
||||
"<cross-script-capture-unary>",
|
||||
"""
|
||||
val delta = 2
|
||||
{ x -> x + delta }
|
||||
""".trimIndent()
|
||||
),
|
||||
Script.defaultImportManager
|
||||
)
|
||||
val unrelatedScript = Compiler.compile(
|
||||
Source(
|
||||
"<cross-script-capture-unrelated>",
|
||||
"""
|
||||
val base = 7
|
||||
base
|
||||
""".trimIndent()
|
||||
),
|
||||
Script.defaultImportManager
|
||||
)
|
||||
|
||||
val scope = Script.newScope()
|
||||
val callable = unaryLambda.execute(scope) as Statement
|
||||
unrelatedScript.execute(scope)
|
||||
|
||||
assertEquals(42, callable.call(scope, ObjInt.of(40)).toInt())
|
||||
assertEquals(42, scope.asFacade().call(callable, Arguments(ObjInt.of(40))).toInt())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun subjectlessWhenReportsScriptError() = runTest {
|
||||
val ex = assertFailsWith<ScriptError> {
|
||||
|
||||
Reference in new issue
Block a user