Kotlin / Kotlin/kotlin-script-examples

Can't bind to engine

Open
#4 1 comment 1 reaction 0 assignees View on GitHub
Dominant language
Kotlin
Stars
339
Forks
48
PR merge metrics
No merged PRs in 30d

Description

import org.junit.Test
import javax.script.ScriptEngineManager
import kotlin.test.assertEquals

class ScriptTest {

@Test
fun testSimpleEval() {
val engine = ScriptEngineManager().getEngineByExtension("kts")!!
val res = engine.eval("2+4")
assertEquals(6,res)
}

@Test
fun testSimpleBinding() {
val engine = ScriptEngineManager().getEngineByExtension("kts")!!
engine.put("hello","world")
val res = engine.eval("hello")
assertEquals("world",res)
}
}

I've got

javax.script.ScriptException: Unresolved reference: hello
at org.jetbrains.kotlin.cli.common.repl.KotlinJsr223JvmScriptEngineBase.compileAndEval(KotlinJsr223JvmScriptEngineBase.kt:65)
at org.jetbrains.kotlin.cli.common.repl.KotlinJsr223JvmScriptEngineBase.eval(KotlinJsr223JvmScriptEngineBase.kt:31)

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by running the shown ScriptTest reproduction with ScriptEngineManager.getEngineByExtension("kts"). Focus on the testSimpleBinding path using engine.put("hello", "world") followed by engine.eval("hello"); done means the evaluation resolves hello and the assertEquals("world", res) test passes.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.