[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:
committed by
Space Team
parent
b13a225949
commit
8bd823de0d
+59
@@ -0,0 +1,59 @@
|
||||
// DIAGNOSTICS: -UNCHECKED_CAST
|
||||
|
||||
// CHECK_TYPE_WITH_EXACT
|
||||
|
||||
// ISSUE: KT-60663
|
||||
/* ATTENTION:
|
||||
* this test is supposed to monitor unclear feature behavior;
|
||||
* an explicit design decision regarding said behavior has not been made at the moment of test creation;
|
||||
* if the behavior of the test changes, please consult with the linked YT ticket
|
||||
* and either add a comment about the change if an explicit design decision is still unavailable
|
||||
* (preferably accompanied by an analysis of the change's reasons)
|
||||
* or remove this disclaimer otherwise
|
||||
*/
|
||||
|
||||
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
|
||||
|
||||
class NestedBuildee<T> {
|
||||
fun nestedYield(arg: T) {}
|
||||
}
|
||||
fun <T> nestedBuild(
|
||||
instructions: NestedBuildee<T>.() -> Unit
|
||||
): NestedBuildee<T> {
|
||||
return NestedBuildee<T>().apply(instructions)
|
||||
}
|
||||
|
||||
// test 1: PTV is in consuming position (yield-case)
|
||||
fun testYield() {
|
||||
val arg: UserKlass = UserKlass()
|
||||
val buildee = <!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>build<!> {
|
||||
nestedBuild {
|
||||
yield(arg)
|
||||
nestedYield(42)
|
||||
}
|
||||
}
|
||||
<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>checkExactType<!><<!CANNOT_INFER_PARAMETER_TYPE!>Buildee<UserKlass><!>>(buildee)
|
||||
}
|
||||
|
||||
// test 2: PTV is in producing position (materialize-case)
|
||||
fun testMaterialize() {
|
||||
fun consume(arg: UserKlass) {}
|
||||
val buildee = <!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>build<!> {
|
||||
nestedBuild {
|
||||
consume(materialize())
|
||||
nestedYield(42)
|
||||
}
|
||||
}
|
||||
<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>checkExactType<!><<!CANNOT_INFER_PARAMETER_TYPE!>Buildee<UserKlass><!>>(buildee)
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
// DIAGNOSTICS: -UNCHECKED_CAST
|
||||
|
||||
// CHECK_TYPE_WITH_EXACT
|
||||
|
||||
// ISSUE: KT-60663
|
||||
/* ATTENTION:
|
||||
* this test is supposed to monitor unclear feature behavior;
|
||||
* an explicit design decision regarding said behavior has not been made at the moment of test creation;
|
||||
* if the behavior of the test changes, please consult with the linked YT ticket
|
||||
* and either add a comment about the change if an explicit design decision is still unavailable
|
||||
* (preferably accompanied by an analysis of the change's reasons)
|
||||
* or remove this disclaimer otherwise
|
||||
*/
|
||||
|
||||
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
|
||||
|
||||
class NestedBuildee<T> {
|
||||
fun nestedYield(arg: T) {}
|
||||
}
|
||||
fun <T> nestedBuild(
|
||||
instructions: NestedBuildee<T>.() -> Unit
|
||||
): NestedBuildee<T> {
|
||||
return NestedBuildee<T>().apply(instructions)
|
||||
}
|
||||
|
||||
// test 1: PTV is in consuming position (yield-case)
|
||||
fun testYield() {
|
||||
val arg: UserKlass = UserKlass()
|
||||
val buildee = <!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>build<!> {
|
||||
nestedBuild {
|
||||
yield(arg)
|
||||
nestedYield(42)
|
||||
}
|
||||
}
|
||||
checkExactType<Buildee<UserKlass>>(<!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>buildee<!>)
|
||||
}
|
||||
|
||||
// test 2: PTV is in producing position (materialize-case)
|
||||
fun testMaterialize() {
|
||||
fun consume(arg: UserKlass) {}
|
||||
val buildee = <!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>build<!> {
|
||||
nestedBuild {
|
||||
consume(materialize())
|
||||
nestedYield(42)
|
||||
}
|
||||
}
|
||||
checkExactType<Buildee<UserKlass>>(<!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>buildee<!>)
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
// FIR_IDENTICAL
|
||||
// DIAGNOSTICS: -UNCHECKED_CAST
|
||||
|
||||
// CHECK_TYPE_WITH_EXACT
|
||||
|
||||
// ISSUE: KT-60274
|
||||
// (also see an analogous codegen test)
|
||||
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user