I might find a bug in kotlin-scripting (v1.3.61 an...
# scripting
l
I might find a bug in kotlin-scripting (v1.3.61 and v1.3.70). The code is as follows:
Copy code
@KotlinScript(fileExtension = "simplescript.kts")
abstract class SimpleScript

fun main() {
    val config = createJvmCompilationConfigurationFromTemplate<SimpleScript> {
        jvm {
            dependenciesFromCurrentContext(wholeClasspath = true)
        }
    }

    val s = """
        println("This is a test!")
    """.trimIndent()

    val res = BasicJvmScriptingHost().eval(s.toScriptSource(), config, null)
    println(res)
}
Running this program, the output is as follows:
Copy code
This is a test!
Success(value=EvaluationResult(returnValue=Unit, configuration=kotlin.script.experimental.api.ScriptEvaluationConfiguration@a9a8cb94), reports=[])
Though the evalution of this script is successful,
EvaluationResult.returnValue
is
Unit
, which is not expected. I try to run this program with kotlin-scripting (v1.3.31), the output is:
Copy code
This is a test!
Success(value=EvaluationResult(returnValue=:  = Script_simplescript@3ddf2a72, configuration=kotlin.script.experimental.api.ScriptEvaluationConfiguration@a4b45b1a), reports=[])
It is clear that the script object (Script_simplescript@3ddf2a72) is stored in
EvaluationResult.returnValue
, which is the desirable behavior for me. Could anyone from JB confirm it? Thanks!
i
This is not kotlin standard
Unit
type, this is the
ResultValue.Unit
, that contains the instance you're looking for. A bit more info is in the issue.
l
By looking through the kotlin-scripting codes, I find the implementation of the script evaluation result value has been changed. This is NOT an issue. I can achieve what I want by changing code like this:
val s = """
println("This is a test!")
this
""".trimIndent()
i
I do not fully understand what you mean. I only can point out that to get the script instance you now can use
EvaluationResult.returnValue.scriptInstance
, regardles of the return value type you're getting.
l
Get it! Thanks!
n
that change tripped me up too when i updated, but i think its better than before
3