Minor. Add tests with returning inline class from SAM adapter

This commit is contained in:
Ilmir Usmanov
2021-03-16 02:31:25 +01:00
parent aff25b3666
commit e47715f52b
11 changed files with 171 additions and 0 deletions
@@ -0,0 +1,24 @@
// TARGET_BACKEND: JVM
// WITH_RUNTIME
// FULL_RUNTIME
// FILE: ResultHandler.java
import kotlin.Result;
@FunctionalInterface
public interface ResultHandler<T> {
Result<T> onResult();
}
// FILE: test.kt
@Suppress("RESULT_CLASS_IN_RETURN_TYPE")
fun doSmth(resultHandler: ResultHandler<Boolean>): Result<Boolean> {
return resultHandler.onResult()
}
fun box(): String {
val res = doSmth { Result.success(true) }
return if (res.isSuccess) "OK" else "FAIL"
}
@@ -0,0 +1,19 @@
// WITH_RUNTIME
// KJS_WITH_FULL_RUNTIME
// IGNORE_BACKEND: WASM
// IGNORE_BACKEND: JVM
inline class Result<T>(val isSuccess: Boolean)
fun interface ResultHandler<T> {
fun onResult(): Result<T>
}
fun doSmth(resultHandler: ResultHandler<Boolean>): Result<Boolean> {
return resultHandler.onResult()
}
fun box(): String {
var res = doSmth { Result(true) }
return if (res.isSuccess) "OK" else "FAIL"
}
@@ -0,0 +1,19 @@
// WITH_RUNTIME
// KJS_WITH_FULL_RUNTIME
// IGNORE_BACKEND: JVM
// IGNORE_BACKEND: WASM
fun interface ResultHandler<T> {
@Suppress("RESULT_CLASS_IN_RETURN_TYPE")
fun onResult(): Result<T>
}
@Suppress("RESULT_CLASS_IN_RETURN_TYPE")
fun doSmth(resultHandler: ResultHandler<Boolean>): Result<Boolean> {
return resultHandler.onResult()
}
fun box(): String {
var res = doSmth { Result.success(true) }
return if (res.isSuccess) "OK" else "FAIL 1"
}