JVM_IR indy-SAM conversions, 1st passing tests

KT-44278 KT-26060 KT-42621
This commit is contained in:
Dmitry Petrov
2021-01-14 17:08:17 +03:00
parent c13949d322
commit 3140cca050
37 changed files with 1144 additions and 58 deletions
@@ -0,0 +1,23 @@
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// SAM_CONVERSIONS: INDY
fun interface KRunnable {
fun run()
}
fun runIt(kr: KRunnable) {
kr.run()
}
class C(var value: String) {
fun fn() {
value = "OK"
}
}
fun box(): String {
val c = C("xxx")
runIt(c::fn)
return c.value
}
@@ -0,0 +1,20 @@
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// SAM_CONVERSIONS: INDY
fun interface KRunnable {
fun run()
}
fun runIt(kr: KRunnable) {
kr.run()
}
class C(var value: String) {
fun test(): String {
runIt { value = "OK" }
return value
}
}
fun box() = C("xxx").test()
@@ -0,0 +1,20 @@
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// SAM_CONVERSIONS: INDY
fun interface KRunnable {
fun run()
}
fun runIt(kr: KRunnable) {
kr.run()
}
class C(var value: String)
fun C.test(): String {
runIt { value = "OK" }
return value
}
fun box() = C("xxx").test()
@@ -0,0 +1,20 @@
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// SAM_CONVERSIONS: INDY
fun interface KRunnable {
fun run()
}
fun runIt(r: KRunnable) {
r.run()
}
var test = "Failed"
fun box(): String {
val ok = "OK"
runIt { test = ok }
return test
}
@@ -0,0 +1,18 @@
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// SAM_CONVERSIONS: INDY
// FILE: capturingIndySam.kt
var test = "Failed"
fun box(): String {
val ok = "OK"
J.run { test = ok }
return test
}
// FILE: J.java
public class J {
public static void run(Runnable r) {
r.run();
}
}
@@ -0,0 +1,46 @@
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// SAM_CONVERSIONS: INDY
// FILE: primitiveVsWrapperInSam.kt
var test = 0
fun tf2(k: Int) { test = k * 10 }
fun tf4() = 5678
fun box(): String {
J.accept42 { k: Int -> test = k }
if (test != 42) return "Failed 1: test=$test"
J.accept42(::tf2)
if (test != 420) return "Failed 2: test=$test"
val t3 = J.get { 1234 }
if (t3 != 1234) return "Failed 3: t3=$t3"
val t4 = J.get(::tf4)
if (t4 != 5678) return "Failed 4: t4=$t4"
return "OK"
}
// FILE: J.java
public class J {
public static void accept42(Sam1 sam) {
sam.accept(42);
}
public static int get(Sam2 sam) {
return sam.get();
}
}
// FILE: Sam1.java
public interface Sam1 {
void accept(Integer x);
}
// FILE: Sam2.java
public interface Sam2 {
Integer get();
}
@@ -0,0 +1,18 @@
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// SAM_CONVERSIONS: INDY
fun interface KRunnable {
fun run()
}
fun runIt(r: KRunnable) {
r.run()
}
var test = "Failed"
fun box(): String {
runIt { test = "OK" }
return test
}
@@ -0,0 +1,17 @@
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// SAM_CONVERSIONS: INDY
// FILE: simpleIndySam.kt
var test = "Failed"
fun box(): String {
J.run { test = "OK" }
return test
}
// FILE: J.java
public class J {
public static void run(Runnable r) {
r.run();
}
}