K2 Scripting: restore some codegen scripting tests for K2

This commit is contained in:
Ilya Chernikov
2023-12-21 17:34:32 +01:00
committed by Space Team
parent a83d2b7a67
commit 3b70b3d92d
17 changed files with 248 additions and 4 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
// TARGET_BACKEND: JVM
// IGNORE_BACKEND_K2: JVM_IR, JS_IR, JS_IR_ES6
// FIR status: scripts aren't supported yet
// FIR status: script declarations are not visible from other sources
// IGNORE_LIGHT_ANALYSIS
// WITH_STDLIB
// FILE: test.kt
+1 -1
View File
@@ -1,6 +1,6 @@
// TARGET_BACKEND: JVM
// IGNORE_BACKEND_K2: JVM_IR, JS_IR, JS_IR_ES6
// FIR status: scripts aren't supported yet
// FIR status: script declarations are not visible from other sources
// IGNORE_LIGHT_ANALYSIS
// WITH_STDLIB
// FILE: test.kt
@@ -0,0 +1,31 @@
// TARGET_BACKEND: JVM
// IGNORE_BACKEND_K1: JVM, JVM_IR, JS_IR, JS_IR_ES6
// IGNORE_LIGHT_ANALYSIS
// WITH_STDLIB
// FILE: test.kt
fun box(): String =
Build.Debug.run { "${c0()}${c1()}" }
// FILE: script.kts
interface Base {
val v: String
fun c0(): Char {
fun getC0() = v[0]
return getC0()
}
}
enum class Build(override val v: String): Base {
Debug("OK"),
Release("NO");
fun c1(): Char {
val g = object {
val c1 = v[1]
}
return g.c1
}
}
+1 -1
View File
@@ -1,6 +1,6 @@
// TARGET_BACKEND: JVM
// IGNORE_BACKEND_K2: JVM_IR, JS_IR, JS_IR_ES6
// FIR status: scripts aren't supported yet
// FIR status: script declarations are not visible from other sources
// IGNORE_LIGHT_ANALYSIS
// WITH_STDLIB
// FILE: test.kt
@@ -1,6 +1,6 @@
// TARGET_BACKEND: JVM
// IGNORE_BACKEND_K2: JVM_IR, JS_IR, JS_IR_ES6
// FIR status: scripts aren't supported yet
// FIR status: script declarations are not visible from other sources
// IGNORE_LIGHT_ANALYSIS
// WITH_STDLIB
// FILE: test.kt
@@ -0,0 +1,14 @@
// TARGET_BACKEND: JVM
// IGNORE_BACKEND_K1: JVM, JVM_IR, JS_IR, JS_IR_ES6
// IGNORE_LIGHT_ANALYSIS
// WITH_STDLIB
// FILE: test.kt
fun box(): String =
Nested().x
// FILE: script.kts
class Nested {
val x = "OK"
}
@@ -0,0 +1,28 @@
// TARGET_BACKEND: JVM_IR
// IGNORE_BACKEND_K1: JS_IR, JS_IR_ES6
// IGNORE_LIGHT_ANALYSIS
// !LANGUAGE: -SkipStandaloneScriptsInSourceRoots
// WITH_STDLIB
// Although this test works in K1 just fine, it is named with the suffix K2 to show that the demonstrated method is the only one
// available so far to call a script from another module.
// In K1 one can do it directly, but this is not the functionality we want to retain
// MODULE: lib
// FILE: script.kts
fun ok() = "OK"
// MODULE: main(lib)
// FILE: test.kt
fun runScriptMethod(name: String, method: String): Any {
val klass = Thread.currentThread().contextClassLoader.loadClass(name)
val constructor = klass.constructors.single()
val instance = constructor.newInstance(emptyArray<String>())
val method = klass.getMethod(method)
return method.invoke(instance)
}
fun box(): String =
runScriptMethod("Script", "ok") as String