[tests] BI (1P&1TV/1TIO): add test data for sinks & sources of type information [1/X]

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

cover member properties as type info sinks;
cover extension functions as type info sinks;
cover extension properties as type info sinks;
cover extension functions as type info sources;
cover extension properties as type info sources;
cover input values of builder arguments as type info sinks;
cover input values of builder arguments as type info sources;
cover return types of builder parameters as type info sources;

relevant issues:
KT-61907
KT-61909
KT-63477
This commit is contained in:
Stanislav Ruban
2023-11-09 14:00:37 +02:00
committed by Space Team
parent 9c2ce475e2
commit 196f5760f8
34 changed files with 1051 additions and 0 deletions
@@ -0,0 +1,41 @@
// FIR_IDENTICAL
// CHECK_TYPE_WITH_EXACT
/* TESTS */
// PTV is in consuming position (yield-case)
fun testYield() {
val arg: UserKlass = UserKlass()
val buildee = build {
yield(arg)
}
// exact type equality check — turns unexpected compile-time behavior into red code
// considered to be non-user-reproducible code for the purposes of these tests
checkExactType<Buildee<UserKlass>>(buildee)
}
// PTV is in producing position (materialize-case)
fun testMaterialize() {
fun consume(arg: UserKlass) {}
val buildee = build {
consume(materialize())
}
// exact type equality check — turns unexpected compile-time behavior into red code
// considered to be non-user-reproducible code for the purposes of these tests
checkExactType<Buildee<UserKlass>>(buildee)
}
/* REQUIRED DECLARATIONS */
class Buildee<CT>
fun <EFT> Buildee<EFT>.yield(arg: EFT) {}
fun <EFT> Buildee<EFT>.materialize(): EFT = null!!
fun <FT> build(
instructions: Buildee<FT>.() -> Unit
): Buildee<FT> {
return Buildee<FT>().apply(instructions)
}
class UserKlass
@@ -0,0 +1,29 @@
// FIR_IDENTICAL
// CHECK_TYPE_WITH_EXACT
/* TESTS */
// PTV is in producing position (materialize-case)
fun testMaterialize() {
fun consume(arg: UserKlass) {}
val buildee = build {
consume(value)
}
// exact type equality check — turns unexpected compile-time behavior into red code
// considered to be non-user-reproducible code for the purposes of these tests
checkExactType<Buildee<UserKlass>>(buildee)
}
/* REQUIRED DECLARATIONS */
class Buildee<CT>
val <EFT> Buildee<EFT>.value: EFT get() = null!!
fun <FT> build(
instructions: Buildee<FT>.() -> Unit
): Buildee<FT> {
return Buildee<FT>().apply(instructions)
}
class UserKlass
@@ -0,0 +1,29 @@
// FIR_IDENTICAL
// CHECK_TYPE_WITH_EXACT
/* TESTS */
// PTV is in producing position (materialize-case)
fun testMaterialize() {
fun consume(arg: UserKlass) {}
val buildee = build {
consume(value)
}
// exact type equality check — turns unexpected compile-time behavior into red code
// considered to be non-user-reproducible code for the purposes of these tests
checkExactType<Buildee<UserKlass>>(buildee)
}
/* REQUIRED DECLARATIONS */
class Buildee<CT> {
val value: CT = null!!
}
fun <FT> build(
instructions: Buildee<FT>.() -> Unit
): Buildee<FT> {
return Buildee<FT>().apply(instructions)
}
class UserKlass
@@ -0,0 +1,31 @@
// FIR_IDENTICAL
// CHECK_TYPE_WITH_EXACT
/* TESTS */
// PTV is in producing position (materialize-case)
fun testMaterialize() {
fun consume(arg: UserKlass) {}
val buildee = build {
consume(variable)
}
// exact type equality check — turns unexpected compile-time behavior into red code
// considered to be non-user-reproducible code for the purposes of these tests
checkExactType<Buildee<UserKlass>>(buildee)
}
/* REQUIRED DECLARATIONS */
class Buildee<CT>
var <EFT> Buildee<EFT>.variable: EFT
get() = null!!
set(value) {}
fun <FT> build(
instructions: Buildee<FT>.() -> Unit
): Buildee<FT> {
return Buildee<FT>().apply(instructions)
}
class UserKlass
@@ -0,0 +1,33 @@
// CHECK_TYPE_WITH_EXACT
// ISSUE: KT-61909
// REASON: unexpected yellow code in K1
/* TESTS */
// PTV is in consuming position (yield-case)
fun testYield() {
val arg: UserKlass = UserKlass()
val buildee = build {
variable = arg
}
// exact type equality check — turns unexpected compile-time behavior into red code
// considered to be non-user-reproducible code for the purposes of these tests
checkExactType<Buildee<UserKlass>>(buildee)
}
/* REQUIRED DECLARATIONS */
class Buildee<CT>
var <EFT> Buildee<EFT>.variable: EFT
get() = null!!
set(value) {}
fun <FT> build(
instructions: Buildee<FT>.() -> Unit
): Buildee<FT> {
return Buildee<FT>().apply(instructions)
}
class UserKlass
@@ -0,0 +1,33 @@
// CHECK_TYPE_WITH_EXACT
// ISSUE: KT-61909
// REASON: unexpected yellow code in K1
/* TESTS */
// PTV is in consuming position (yield-case)
fun testYield() {
val arg: UserKlass = UserKlass()
val buildee = <!INFERRED_INTO_DECLARED_UPPER_BOUNDS!>build<!> {
variable = arg
}
// exact type equality check — turns unexpected compile-time behavior into red code
// considered to be non-user-reproducible code for the purposes of these tests
checkExactType<Buildee<UserKlass>>(<!TYPE_MISMATCH, TYPE_MISMATCH!>buildee<!>)
}
/* REQUIRED DECLARATIONS */
class Buildee<CT>
var <EFT> Buildee<EFT>.variable: EFT
get() = null!!
set(value) {}
fun <FT> build(
instructions: Buildee<FT>.() -> Unit
): Buildee<FT> {
return Buildee<FT>().apply(instructions)
}
class UserKlass
@@ -0,0 +1,29 @@
// FIR_IDENTICAL
// CHECK_TYPE_WITH_EXACT
/* TESTS */
// PTV is in producing position (materialize-case)
fun testMaterialize() {
fun consume(arg: UserKlass) {}
val buildee = build {
consume(variable)
}
// exact type equality check — turns unexpected compile-time behavior into red code
// considered to be non-user-reproducible code for the purposes of these tests
checkExactType<Buildee<UserKlass>>(buildee)
}
/* REQUIRED DECLARATIONS */
class Buildee<CT> {
var variable: CT = null!!
}
fun <FT> build(
instructions: Buildee<FT>.() -> Unit
): Buildee<FT> {
return Buildee<FT>().apply(instructions)
}
class UserKlass
@@ -0,0 +1,31 @@
// CHECK_TYPE_WITH_EXACT
// ISSUE: KT-61907
// REASON: unexpected red code in K1
/* TESTS */
// PTV is in consuming position (yield-case)
fun testYield() {
val arg: UserKlass = UserKlass()
val buildee = build {
variable = arg
}
// exact type equality check — turns unexpected compile-time behavior into red code
// considered to be non-user-reproducible code for the purposes of these tests
checkExactType<Buildee<UserKlass>>(buildee)
}
/* REQUIRED DECLARATIONS */
class Buildee<CT> {
var variable: CT = null!!
}
fun <FT> build(
instructions: Buildee<FT>.() -> Unit
): Buildee<FT> {
return Buildee<FT>().apply(instructions)
}
class UserKlass
@@ -0,0 +1,31 @@
// CHECK_TYPE_WITH_EXACT
// ISSUE: KT-61907
// REASON: unexpected red code in K1
/* TESTS */
// PTV is in consuming position (yield-case)
fun testYield() {
val arg: UserKlass = UserKlass()
val buildee = <!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>build<!> {
variable = <!TYPE_MISMATCH!>arg<!>
}
// exact type equality check — turns unexpected compile-time behavior into red code
// considered to be non-user-reproducible code for the purposes of these tests
checkExactType<Buildee<UserKlass>>(<!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>buildee<!>)
}
/* REQUIRED DECLARATIONS */
class Buildee<CT> {
var variable: CT = null!!
}
fun <FT> build(
instructions: Buildee<FT>.() -> Unit
): Buildee<FT> {
return Buildee<FT>().apply(instructions)
}
class UserKlass
@@ -0,0 +1,27 @@
// FIR_IDENTICAL
// CHECK_TYPE_WITH_EXACT
/* TESTS */
// PTV is in producing position (materialize-case)
fun testMaterialize() {
fun consume(arg: Buildee<UserKlass>) {}
val buildee = build {
consume(it)
}
// exact type equality check — turns unexpected compile-time behavior into red code
// considered to be non-user-reproducible code for the purposes of these tests
checkExactType<Buildee<UserKlass>>(buildee)
}
/* REQUIRED DECLARATIONS */
class Buildee<CT>
fun <FT> build(
instructions: (Buildee<FT>) -> Unit
): Buildee<FT> {
return Buildee<FT>().apply(instructions)
}
class UserKlass
@@ -0,0 +1,27 @@
// FIR_IDENTICAL
// CHECK_TYPE_WITH_EXACT
/* TESTS */
// PTV is in producing position (materialize-case)
fun testMaterialize() {
fun consume(arg: Buildee<UserKlass>) {}
val buildee = build {
consume(this)
}
// exact type equality check — turns unexpected compile-time behavior into red code
// considered to be non-user-reproducible code for the purposes of these tests
checkExactType<Buildee<UserKlass>>(buildee)
}
/* REQUIRED DECLARATIONS */
class Buildee<CT>
fun <FT> build(
instructions: Buildee<FT>.() -> Unit
): Buildee<FT> {
return Buildee<FT>().apply(instructions)
}
class UserKlass
@@ -0,0 +1,28 @@
// FIR_IDENTICAL
// CHECK_TYPE_WITH_EXACT
/* TESTS */
// PTV is in producing position (materialize-case)
fun testMaterialize() {
val buildee = build {
this.typeInfoSourcingFunction()
}
// exact type equality check — turns unexpected compile-time behavior into red code
// considered to be non-user-reproducible code for the purposes of these tests
checkExactType<Buildee<UserKlass>>(buildee)
}
/* REQUIRED DECLARATIONS */
class Buildee<CT>
fun <FT> build(
instructions: Buildee<FT>.() -> Unit
): Buildee<FT> {
return Buildee<FT>().apply(instructions)
}
class UserKlass
fun Buildee<UserKlass>.typeInfoSourcingFunction() {}
@@ -0,0 +1,41 @@
// FIR_IDENTICAL
// CHECK_TYPE_WITH_EXACT
/* TESTS */
// PTV is in producing position (materialize-case) and passed to an immutable extension property
fun testMaterializeWithImmutableProperty() {
val buildee = build {
this.typeInfoSourcingValue
}
// exact type equality check — turns unexpected compile-time behavior into red code
// considered to be non-user-reproducible code for the purposes of these tests
checkExactType<Buildee<UserKlass>>(buildee)
}
// PTV is in producing position (materialize-case) and passed to a mutable extension property
fun testMaterializeWithMutableProperty() {
val buildee = build {
this.typeInfoSourcingVariable
}
// exact type equality check — turns unexpected compile-time behavior into red code
// considered to be non-user-reproducible code for the purposes of these tests
checkExactType<Buildee<UserKlass>>(buildee)
}
/* REQUIRED DECLARATIONS */
class Buildee<CT>
fun <FT> build(
instructions: Buildee<FT>.() -> Unit
): Buildee<FT> {
return Buildee<FT>().apply(instructions)
}
class UserKlass
val Buildee<UserKlass>.typeInfoSourcingValue: UserKlass get() = UserKlass()
var Buildee<UserKlass>.typeInfoSourcingVariable: UserKlass
get() = UserKlass()
set(value) {}
@@ -0,0 +1,28 @@
// FIR_IDENTICAL
// CHECK_TYPE_WITH_EXACT
/* TESTS */
// PTV is in consuming position (yield-case)
fun testYield() {
val buildee = build {
yield(it)
}
// exact type equality check — turns unexpected compile-time behavior into red code
// considered to be non-user-reproducible code for the purposes of these tests
checkExactType<Buildee<UserKlass>>(buildee)
}
/* REQUIRED DECLARATIONS */
class Buildee<CT> {
fun yield(arg: CT) {}
}
fun <FT> build(
instructions: Buildee<FT>.(UserKlass) -> Unit
): Buildee<FT> {
return Buildee<FT>().apply { this.instructions(UserKlass()) }
}
class UserKlass
@@ -0,0 +1,28 @@
// FIR_IDENTICAL
// CHECK_TYPE_WITH_EXACT
/* TESTS */
// PTV is in consuming position (yield-case)
fun testYield() {
val buildee = build {
it.yield(this)
}
// exact type equality check — turns unexpected compile-time behavior into red code
// considered to be non-user-reproducible code for the purposes of these tests
checkExactType<Buildee<UserKlass>>(buildee)
}
/* REQUIRED DECLARATIONS */
class Buildee<CT> {
fun yield(arg: CT) {}
}
fun <FT> build(
instructions: UserKlass.(Buildee<FT>) -> Unit
): Buildee<FT> {
return Buildee<FT>().apply { UserKlass().instructions(this) }
}
class UserKlass
@@ -0,0 +1,38 @@
// FIR_IDENTICAL
// CHECK_TYPE_WITH_EXACT
/* TESTS */
// PTV is returned as a last statement of the builder argument
fun testLastStatementReturn() {
val buildee = build {
materialize()
}
// exact type equality check — turns unexpected compile-time behavior into red code
// considered to be non-user-reproducible code for the purposes of these tests
checkExactType<Buildee<UserKlass>>(buildee)
}
// PTV is returned explicitly
fun testExplicitReturn() {
val buildee = build {
return@build materialize()
}
// exact type equality check — turns unexpected compile-time behavior into red code
// considered to be non-user-reproducible code for the purposes of these tests
checkExactType<Buildee<UserKlass>>(buildee)
}
/* REQUIRED DECLARATIONS */
class Buildee<CT> {
fun materialize(): CT = null!!
}
fun <FT> build(
instructions: Buildee<FT>.() -> UserKlass
): Buildee<FT> {
return Buildee<FT>().apply { this.instructions() }
}
class UserKlass
@@ -0,0 +1,26 @@
// FIR_IDENTICAL
// CHECK_TYPE_WITH_EXACT
/* TESTS */
// PTV is returned explicitly
fun testExplicitReturn() {
val buildee = build {
return@build materialize()
}
// exact type equality check — turns unexpected compile-time behavior into red code
// considered to be non-user-reproducible code for the purposes of these tests
checkExactType<Buildee<Unit>>(buildee)
}
/* REQUIRED DECLARATIONS */
class Buildee<CT> {
fun materialize(): CT = null!!
}
fun <FT> build(
instructions: Buildee<FT>.() -> Unit
): Buildee<FT> {
return Buildee<FT>().apply { this.instructions() }
}
@@ -0,0 +1,35 @@
// CHECK_TYPE_WITH_EXACT
// ISSUE: KT-63477
/* 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
*/
/* TESTS */
// PTV is returned as a last statement of the builder argument
fun testLastStatementReturn() {
val buildee = <!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>build<!> {
materialize()
}
// exact type equality check — turns unexpected compile-time behavior into red code
// considered to be non-user-reproducible code for the purposes of these tests
<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>checkExactType<!><<!CANNOT_INFER_PARAMETER_TYPE!>Buildee<Unit><!>>(buildee)
}
/* REQUIRED DECLARATIONS */
class Buildee<CT> {
fun materialize(): CT = null!!
}
fun <FT> build(
instructions: Buildee<FT>.() -> Unit
): Buildee<FT> {
return Buildee<FT>().apply { this.instructions() }
}
@@ -0,0 +1,35 @@
// CHECK_TYPE_WITH_EXACT
// ISSUE: KT-63477
/* 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
*/
/* TESTS */
// PTV is returned as a last statement of the builder argument
fun testLastStatementReturn() {
val buildee = <!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>build<!> {
materialize()
}
// exact type equality check — turns unexpected compile-time behavior into red code
// considered to be non-user-reproducible code for the purposes of these tests
checkExactType<Buildee<Unit>>(<!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>buildee<!>)
}
/* REQUIRED DECLARATIONS */
class Buildee<CT> {
fun materialize(): CT = null!!
}
fun <FT> build(
instructions: Buildee<FT>.() -> Unit
): Buildee<FT> {
return Buildee<FT>().apply { this.instructions() }
}