Move tests for builder inference into the corresponding directory
This commit is contained in:
Vendored
+20
@@ -0,0 +1,20 @@
|
||||
// DONT_TARGET_EXACT_BACKEND: WASM
|
||||
// WASM_MUTE_REASON: STDLIB_COLLECTIONS
|
||||
// !LANGUAGE: +NewInference
|
||||
// !DIAGNOSTICS: -EXPERIMENTAL_API_USAGE_ERROR -UNUSED_EXPRESSION
|
||||
// WITH_RUNTIME
|
||||
|
||||
@OptIn(ExperimentalStdlibApi::class)
|
||||
fun test(s: String?): Int {
|
||||
val list = buildList {
|
||||
s?.let(::add)
|
||||
}
|
||||
return list.size
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return when (test("hello")) {
|
||||
1 -> "OK"
|
||||
else -> "Error"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
// ISSUE: KT-41164
|
||||
// WITH_RUNTIME
|
||||
|
||||
import kotlin.experimental.ExperimentalTypeInference
|
||||
|
||||
interface MyProducerScope<in E>
|
||||
interface MyFlow<out T>
|
||||
|
||||
fun <K> select(x: K, y: K): K = x
|
||||
@OptIn(ExperimentalTypeInference::class)
|
||||
fun <T> myCallbackFlow(@BuilderInference block: MyProducerScope<T>.() -> Unit): MyFlow<T> = null!!
|
||||
fun MyProducerScope<*>.myAwaitClose(block: () -> Unit = {}) {}
|
||||
fun <E> myEmptyFlow(): MyFlow<E> = null!!
|
||||
|
||||
fun test(): MyFlow<Int> {
|
||||
return select(
|
||||
myCallbackFlow {
|
||||
myAwaitClose {}
|
||||
},
|
||||
myEmptyFlow()
|
||||
)
|
||||
}
|
||||
|
||||
fun box(): String = "OK"
|
||||
Vendored
+30
@@ -0,0 +1,30 @@
|
||||
// !LANGUAGE: +NewInference
|
||||
// WITH_RUNTIME
|
||||
// Issue: KT-36371
|
||||
|
||||
import kotlin.experimental.ExperimentalTypeInference
|
||||
|
||||
class Foo(val string: String? = null)
|
||||
|
||||
class Builder<T> {
|
||||
private var resolver: ((Foo) -> T)? = null
|
||||
fun build() = resolver!!
|
||||
|
||||
fun resolve(resolver: (Foo) -> T) {
|
||||
this.resolver = resolver
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalTypeInference::class)
|
||||
fun <T> build(@BuilderInference configure: Builder<T>.() -> Unit) =
|
||||
Builder<T>().apply(configure).build()
|
||||
|
||||
fun box(): String {
|
||||
val resolver = build {
|
||||
resolve { it.string }
|
||||
}
|
||||
|
||||
resolver(Foo())
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
// DONT_TARGET_EXACT_BACKEND: WASM
|
||||
// WASM_MUTE_REASON: COROUTINES
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
// IGNORE_BACKEND: JS_IR
|
||||
// IGNORE_BACKEND: NATIVE
|
||||
// KJS_WITH_FULL_RUNTIME
|
||||
// WITH_RUNTIME
|
||||
// WITH_COROUTINES
|
||||
|
||||
import helpers.*
|
||||
import kotlin.coroutines.*
|
||||
|
||||
suspend fun foo() {
|
||||
val x = sequence {
|
||||
yield(1)
|
||||
::`yield`
|
||||
}
|
||||
}
|
||||
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
c.startCoroutine(EmptyContinuation)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
builder { foo() }
|
||||
return "OK"
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
import kotlin.experimental.ExperimentalTypeInference
|
||||
|
||||
class TypeDefinition<K : Any> {
|
||||
fun parse(parser: (serializedValue: String) -> K?): Unit {}
|
||||
fun serialize(parser: (value: K) -> Any?): Unit {}
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalTypeInference::class)
|
||||
fun <T : Any> defineType(@BuilderInference definition: TypeDefinition<T>.() -> Unit): Unit {}
|
||||
|
||||
fun test() {
|
||||
defineType {
|
||||
parse { it as Int }
|
||||
serialize { it.toString() }
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
test()
|
||||
return "OK"
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// WITH_RUNTIME
|
||||
|
||||
class Foo<A>
|
||||
|
||||
fun <K> bar(x: Foo<K>): Unit {}
|
||||
|
||||
fun <E> foo(block: (Foo<E>) -> Unit): E = null as E
|
||||
|
||||
interface FlowCollector<T> {
|
||||
fun emit(value: T)
|
||||
}
|
||||
|
||||
@Suppress("EXPERIMENTAL_API_USAGE_ERROR")
|
||||
fun <I> flow(@BuilderInference block: FlowCollector<I>.() -> Unit): I = null as I
|
||||
|
||||
fun adapt(): Unit = flow {
|
||||
emit(foo { coroutine -> bar(coroutine) })
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
adapt()
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user