JVM_IR: add a test for when(enum) binary compatibility

This commit is contained in:
pyos
2022-04-06 13:10:12 +02:00
committed by Alexander Udalov
parent 518a6dec8c
commit d61e7db937
5 changed files with 38 additions and 0 deletions
@@ -0,0 +1,4 @@
package test
enum class E1 { A, C, B, D }
enum class E2 { A, B }
@@ -0,0 +1,4 @@
package test
enum class E1 { A, B, C }
enum class E2 { A, B, C }
@@ -0,0 +1,18 @@
import test.*
fun f1(x: E1) = when (x) {
E1.A -> "A"
E1.B -> "B"
E1.C -> "C"
}
fun f2(x: E2) = when (x) {
E2.A -> "A"
E2.B -> "B"
E2.C -> "C"
}
fun run(): String {
val c2 = try { f2(E2.C) } catch (e: java.lang.NoSuchFieldError) { "" }
return f1(E1.A) + f1(E1.B) + f1(E1.C) + f2(E2.A) + f2(E2.B) + c2
}
@@ -519,6 +519,17 @@ class CompileKotlinAgainstCustomBinariesTest : AbstractKotlinCompilerIntegration
.loadClass("SourceKt").getDeclaredMethod("run").invoke(null)
}
fun testChangedEnumsInLibrary() {
val oldLibrary = compileLibrary("old", checkKotlinOutput = {})
val newLibrary = compileLibrary("new", checkKotlinOutput = {})
compileKotlin("source.kt", tmpdir, listOf(oldLibrary))
val result =
URLClassLoader(arrayOf(newLibrary.toURI().toURL(), tmpdir.toURI().toURL()), ForTestCompileRuntime.runtimeJarClassLoader())
.loadClass("SourceKt").getDeclaredMethod("run").invoke(null) as String
assertEquals("ABCAB", result)
}
fun testClassFromJdkInLibrary() {
val library = compileLibrary("library")
compileKotlin("source.kt", tmpdir, listOf(library))