[tests] BI (1P&1TV/1TIO): add tests for contexts of source-sink feeds

single builder parameter
single postponed type variable
single origin of type information

relevant issues:
KT-60274
KT-60663
This commit is contained in:
Stanislav Ruban
2023-07-25 12:42:52 +03:00
committed by Space Team
parent b13a225949
commit 8bd823de0d
28 changed files with 1097 additions and 0 deletions
@@ -0,0 +1,51 @@
// IGNORE_BACKEND: NATIVE
// IGNORE_BACKEND: WASM
// IGNORE_BACKEND: JS, JS_IR, JS_IR_ES6
// IGNORE_LIGHT_ANALYSIS
// CHECK_TYPE_WITH_EXACT
class Buildee<CT> {
fun yield(arg: CT) {}
fun materialize(): CT = UserKlass() as CT
}
fun <FT> build(
instructions: Buildee<FT>.() -> Unit
): Buildee<FT> {
return Buildee<FT>().apply(instructions)
}
class UserKlass
// test 1: PTV is in consuming position (yield-case)
fun testYield() {
val arg: UserKlass = UserKlass()
val buildee = build {
object {
init {
yield(arg)
}
}
}
checkExactType<Buildee<UserKlass>>(buildee)
}
// test 2: PTV is in producing position (materialize-case)
fun testMaterialize() {
fun consume(arg: UserKlass) {}
val buildee = build {
object {
init {
consume(materialize())
}
}
}
checkExactType<Buildee<UserKlass>>(buildee)
}
fun box(): String {
testYield()
testMaterialize()
return "OK"
}
@@ -0,0 +1,49 @@
// IGNORE_BACKEND: NATIVE
// IGNORE_BACKEND: WASM
// IGNORE_BACKEND: JS, JS_IR, JS_IR_ES6
// IGNORE_LIGHT_ANALYSIS
// CHECK_TYPE_WITH_EXACT
class Buildee<CT> {
fun yield(arg: CT) {}
fun materialize(): CT = UserKlass() as CT
}
fun <FT> build(
instructions: Buildee<FT>.() -> Unit
): Buildee<FT> {
return Buildee<FT>().apply(instructions)
}
class UserKlass
fun execute(action: () -> Unit) {}
// test 1: PTV is in consuming position (yield-case)
fun testYield() {
val arg: UserKlass = UserKlass()
val buildee = build {
execute {
yield(arg)
}
}
checkExactType<Buildee<UserKlass>>(buildee)
}
// test 2: PTV is in producing position (materialize-case)
fun testMaterialize() {
fun consume(arg: UserKlass) {}
val buildee = build {
execute {
consume(materialize())
}
}
checkExactType<Buildee<UserKlass>>(buildee)
}
fun box(): String {
testYield()
testMaterialize()
return "OK"
}
@@ -0,0 +1,41 @@
// IGNORE_BACKEND_K2: NATIVE
// IGNORE_BACKEND_K2: WASM
// IGNORE_BACKEND_K2: JS, JS_IR, JS_IR_ES6
// IGNORE_LIGHT_ANALYSIS
// CHECK_TYPE_WITH_EXACT
// IGNORE_BACKEND_K1: ANY
// ISSUE: KT-60274
import kotlin.reflect.KProperty
class Buildee<CT> {
fun materialize(): CT = UserKlass() as CT
}
fun <FT> build(
instructions: Buildee<FT>.() -> Unit
): Buildee<FT> {
return Buildee<FT>().apply(instructions)
}
class UserKlass
class Delegate<T>(private val value: T) {
operator fun getValue(reference: Nothing?, property: KProperty<*>): T = value
}
fun testMaterialize() {
fun consume(arg: UserKlass) {}
val buildee = build {
val temp by Delegate(materialize())
consume(temp)
}
checkExactType<Buildee<UserKlass>>(buildee)
}
fun box(): String {
testMaterialize()
return "OK"
}
@@ -0,0 +1,38 @@
// IGNORE_BACKEND: NATIVE
// IGNORE_BACKEND: WASM
// IGNORE_BACKEND: JS, JS_IR, JS_IR_ES6
// IGNORE_LIGHT_ANALYSIS
// CHECK_TYPE_WITH_EXACT
import kotlin.reflect.KProperty
class Buildee<CT> {
fun yield(arg: CT) {}
}
fun <FT> build(
instructions: Buildee<FT>.() -> Unit
): Buildee<FT> {
return Buildee<FT>().apply(instructions)
}
class UserKlass
class Delegate<T>(private val value: T) {
operator fun getValue(reference: Nothing?, property: KProperty<*>): T = value
}
fun testYield() {
val arg: UserKlass = UserKlass()
val buildee = build {
val temp by Delegate(arg)
yield(temp)
}
checkExactType<Buildee<UserKlass>>(buildee)
}
fun box(): String {
testYield()
return "OK"
}
@@ -0,0 +1,45 @@
// IGNORE_BACKEND: NATIVE
// IGNORE_BACKEND: WASM
// IGNORE_BACKEND: JS, JS_IR, JS_IR_ES6
// IGNORE_LIGHT_ANALYSIS
// CHECK_TYPE_WITH_EXACT
class Buildee<CT> {
fun yield(arg: CT) {}
fun materialize(): CT = UserKlass() as CT
}
fun <FT> build(
instructions: Buildee<FT>.() -> Unit
): Buildee<FT> {
return Buildee<FT>().apply(instructions)
}
class UserKlass
// test 1: PTV is in consuming position (yield-case)
fun testYield() {
val arg: UserKlass = UserKlass()
val buildee = build {
val temp = arg
yield(temp)
}
checkExactType<Buildee<UserKlass>>(buildee)
}
// test 2: PTV is in producing position (materialize-case)
fun testMaterialize() {
fun consume(arg: UserKlass) {}
val buildee = build {
val temp = materialize()
consume(temp)
}
checkExactType<Buildee<UserKlass>>(buildee)
}
fun box(): String {
testYield()
testMaterialize()
return "OK"
}