JVM_IR indy-SAM: function reference to Java interface
This commit is contained in:
+20
@@ -0,0 +1,20 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// JVM_TARGET: 1.8
|
||||
// SAM_CONVERSIONS: INDY
|
||||
// FILE: adaptedFunRefWithCoercionToUnit.kt
|
||||
var ok = "Failed"
|
||||
|
||||
fun test(s: String): Int {
|
||||
ok = s
|
||||
return 42
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
Sam(::test).foo("OK")
|
||||
return ok
|
||||
}
|
||||
|
||||
// FILE: Sam.java
|
||||
public interface Sam {
|
||||
void foo(String s);
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// JVM_TARGET: 1.8
|
||||
// SAM_CONVERSIONS: INDY
|
||||
// FILE: adaptedFunRefWithDefaultParameters.kt
|
||||
var ok = "Failed"
|
||||
|
||||
fun test(s1: String, s2: String = "K") {
|
||||
ok = s1 + s2
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
Sam(::test).foo("O")
|
||||
return ok
|
||||
}
|
||||
|
||||
// FILE: Sam.java
|
||||
public interface Sam {
|
||||
void foo(String s);
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// JVM_TARGET: 1.8
|
||||
// SAM_CONVERSIONS: INDY
|
||||
// FILE: adaptedFunRefWithVararg.kt
|
||||
var ok = "Failed"
|
||||
|
||||
fun test(vararg ss: String) {
|
||||
ok = ss[0]
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
Sam(::test).foo("OK")
|
||||
return ok
|
||||
}
|
||||
|
||||
// FILE: Sam.java
|
||||
public interface Sam {
|
||||
void foo(String s);
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// JVM_TARGET: 1.8
|
||||
// SAM_CONVERSIONS: INDY
|
||||
// FILE: boundExtFun.kt
|
||||
fun String.k(s: String) = this + s + "K"
|
||||
|
||||
fun box() = Sam("O"::k).get("")
|
||||
// NB simply '::k' is a compilation error
|
||||
|
||||
// FILE: Sam.java
|
||||
public interface Sam {
|
||||
String get(String s);
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// JVM_TARGET: 1.8
|
||||
// SAM_CONVERSIONS: INDY
|
||||
// FILE: boundInnerConstructorRef.kt
|
||||
class Outer(val s1: String) {
|
||||
inner class Inner(val s2: String) {
|
||||
fun t() = s1 + s2
|
||||
}
|
||||
}
|
||||
|
||||
fun box() = Sam(Outer("O")::Inner).get("K").t()
|
||||
|
||||
// FILE: Sam.java
|
||||
public interface Sam {
|
||||
Outer.Inner get(String s);
|
||||
}
|
||||
Vendored
+15
@@ -0,0 +1,15 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// JVM_TARGET: 1.8
|
||||
// SAM_CONVERSIONS: INDY
|
||||
// FILE: boundLocalExtFun.kt
|
||||
fun box(): String {
|
||||
fun String.k(s: String) = this + s + "K"
|
||||
|
||||
return Sam("O"::k).get("")
|
||||
// NB simply '::k' is a compilation error
|
||||
}
|
||||
|
||||
// FILE: Sam.java
|
||||
public interface Sam {
|
||||
String get(String s);
|
||||
}
|
||||
Vendored
+14
@@ -0,0 +1,14 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// JVM_TARGET: 1.8
|
||||
// SAM_CONVERSIONS: INDY
|
||||
// FILE: boundMemberRef.kt
|
||||
class C(val t: String) {
|
||||
fun test() = t
|
||||
}
|
||||
|
||||
fun box() = Sam(C("OK")::test).get()
|
||||
|
||||
// FILE: Sam.java
|
||||
public interface Sam {
|
||||
String get();
|
||||
}
|
||||
Vendored
+12
@@ -0,0 +1,12 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// JVM_TARGET: 1.8
|
||||
// SAM_CONVERSIONS: INDY
|
||||
// FILE: constructorRef.kt
|
||||
class C(val t: String)
|
||||
|
||||
fun box() = Sam(::C).get("OK").t
|
||||
|
||||
// FILE: Sam.java
|
||||
public interface Sam {
|
||||
C get(String s);
|
||||
}
|
||||
Vendored
+20
@@ -0,0 +1,20 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// JVM_TARGET: 1.8
|
||||
// SAM_CONVERSIONS: INDY
|
||||
// FILE: enhancedNullability.kt
|
||||
fun mul2(x: Int) = x * 2
|
||||
|
||||
fun box(): String {
|
||||
val t = Sam(::mul2).get(21)
|
||||
if (t != 42)
|
||||
return "Failed: t=$t"
|
||||
return "OK"
|
||||
}
|
||||
|
||||
// FILE: Sam.java
|
||||
import org.jetbrains.annotations.*;
|
||||
|
||||
public interface Sam {
|
||||
@NotNull Integer get(@NotNull Integer arg);
|
||||
}
|
||||
Vendored
+16
@@ -0,0 +1,16 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// JVM_TARGET: 1.8
|
||||
// SAM_CONVERSIONS: INDY
|
||||
// FILE: innerConstructorRef.kt
|
||||
class Outer(val s1: String) {
|
||||
inner class Inner(val s2: String) {
|
||||
fun t() = s1 + s2
|
||||
}
|
||||
}
|
||||
|
||||
fun box() = Sam(Outer::Inner).get(Outer("O"), "K").t()
|
||||
|
||||
// FILE: Sam.java
|
||||
public interface Sam {
|
||||
Outer.Inner get(Outer outer, String s);
|
||||
}
|
||||
Vendored
+13
@@ -0,0 +1,13 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// JVM_TARGET: 1.8
|
||||
// SAM_CONVERSIONS: INDY
|
||||
// FILE: localFunction1.kt
|
||||
fun box(): String {
|
||||
fun ok() = "OK"
|
||||
return Sam(::ok).get()
|
||||
}
|
||||
|
||||
// FILE: Sam.java
|
||||
public interface Sam {
|
||||
String get();
|
||||
}
|
||||
Vendored
+14
@@ -0,0 +1,14 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// JVM_TARGET: 1.8
|
||||
// SAM_CONVERSIONS: INDY
|
||||
// FILE: localFunction2.kt
|
||||
fun box(): String {
|
||||
val t = "O"
|
||||
fun ok() = t + "K"
|
||||
return Sam(::ok).get()
|
||||
}
|
||||
|
||||
// FILE: Sam.java
|
||||
public interface Sam {
|
||||
String get();
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// JVM_TARGET: 1.8
|
||||
// SAM_CONVERSIONS: INDY
|
||||
// FILE: memberRef.kt
|
||||
class C(val t: String) {
|
||||
fun test() = t
|
||||
}
|
||||
|
||||
fun box() = Sam(C::test).get(C("OK"))
|
||||
|
||||
// FILE: Sam.java
|
||||
public interface Sam {
|
||||
String get(C c);
|
||||
}
|
||||
Vendored
+23
@@ -0,0 +1,23 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// JVM_TARGET: 1.8
|
||||
// SAM_CONVERSIONS: INDY
|
||||
// WITH_RUNTIME
|
||||
// FILE: JavaRunner.java
|
||||
public class JavaRunner {
|
||||
public static void runTwice(Runnable runnable) {
|
||||
runnable.run();
|
||||
runnable.run();
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: nonTrivialReceiver.kt
|
||||
class A() {
|
||||
fun f() {}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var x = 0
|
||||
JavaRunner.runTwice({ x++; A() }()::f)
|
||||
if (x != 1) return "Fail"
|
||||
return "OK"
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// JVM_TARGET: 1.8
|
||||
// SAM_CONVERSIONS: INDY
|
||||
// FILE: simple.kt
|
||||
fun ok() = "OK"
|
||||
|
||||
fun box() = Sam(::ok).get()
|
||||
|
||||
// FILE: Sam.java
|
||||
public interface Sam {
|
||||
String get();
|
||||
}
|
||||
Reference in New Issue
Block a user