Move tests for builder inference into the corresponding directory

This commit is contained in:
Victor Petukhov
2020-12-23 14:29:03 +03:00
parent 9b148325fe
commit 39e579db91
13 changed files with 43 additions and 0 deletions
@@ -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"
@@ -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"
}
@@ -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"
}
@@ -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"
}
@@ -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"
}