[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,38 @@
fun box(): String {
testYield()
testMaterialize()
return "OK"
}
/* TESTS */
// PTV is in consuming position (yield-case)
fun testYield() {
val arg: UserKlass = UserKlass()
build {
yield(arg)
}
}
// PTV is in producing position (materialize-case)
fun testMaterialize() {
fun consume(arg: UserKlass) {}
build {
consume(materialize())
}
}
/* REQUIRED DECLARATIONS */
class Buildee<CT>
fun <EFT> Buildee<EFT>.yield(arg: EFT) {}
fun <EFT> Buildee<EFT>.materialize(): EFT = UserKlass() as EFT
fun <FT> build(
instructions: Buildee<FT>.() -> Unit
): Buildee<FT> {
return Buildee<FT>().apply(instructions)
}
class UserKlass
@@ -0,0 +1,28 @@
fun box(): String {
testMaterialize()
return "OK"
}
/* TESTS */
// PTV is in producing position (materialize-case)
fun testMaterialize() {
fun consume(arg: UserKlass) {}
build {
consume(value)
}
}
/* REQUIRED DECLARATIONS */
class Buildee<CT>
val <EFT> Buildee<EFT>.value: EFT get() = UserKlass() as EFT
fun <FT> build(
instructions: Buildee<FT>.() -> Unit
): Buildee<FT> {
return Buildee<FT>().apply(instructions)
}
class UserKlass
@@ -0,0 +1,28 @@
fun box(): String {
testMaterialize()
return "OK"
}
/* TESTS */
// PTV is in producing position (materialize-case)
fun testMaterialize() {
fun consume(arg: UserKlass) {}
build {
consume(value)
}
}
/* REQUIRED DECLARATIONS */
class Buildee<CT> {
val value: CT = UserKlass() as CT
}
fun <FT> build(
instructions: Buildee<FT>.() -> Unit
): Buildee<FT> {
return Buildee<FT>().apply(instructions)
}
class UserKlass
@@ -0,0 +1,30 @@
fun box(): String {
testMaterialize()
return "OK"
}
/* TESTS */
// PTV is in producing position (materialize-case)
fun testMaterialize() {
fun consume(arg: UserKlass) {}
build {
consume(variable)
}
}
/* REQUIRED DECLARATIONS */
class Buildee<CT>
var <EFT> Buildee<EFT>.variable: EFT
get() = UserKlass() as EFT
set(value) {}
fun <FT> build(
instructions: Buildee<FT>.() -> Unit
): Buildee<FT> {
return Buildee<FT>().apply(instructions)
}
class UserKlass
@@ -0,0 +1,36 @@
// ISSUE: KT-61909
// REASON: unexpected yellow code in K1 (see corresponding diagnostic test)
// IGNORE_LIGHT_ANALYSIS
// REASON: unexpected red code (false-positive NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER in testYield)
fun box(): String {
testYield()
return "OK"
}
/* TESTS */
// PTV is in consuming position (yield-case)
fun testYield() {
val arg: UserKlass = UserKlass()
build {
variable = arg
}
}
/* REQUIRED DECLARATIONS */
class Buildee<CT>
var <EFT> Buildee<EFT>.variable: EFT
get() = UserKlass() as EFT
set(value) {}
fun <FT> build(
instructions: Buildee<FT>.() -> Unit
): Buildee<FT> {
return Buildee<FT>().apply(instructions)
}
class UserKlass
@@ -0,0 +1,28 @@
fun box(): String {
testMaterialize()
return "OK"
}
/* TESTS */
// PTV is in producing position (materialize-case)
fun testMaterialize() {
fun consume(arg: UserKlass) {}
build {
consume(variable)
}
}
/* REQUIRED DECLARATIONS */
class Buildee<CT> {
var variable: CT = UserKlass() as CT
}
fun <FT> build(
instructions: Buildee<FT>.() -> Unit
): Buildee<FT> {
return Buildee<FT>().apply(instructions)
}
class UserKlass
@@ -0,0 +1,32 @@
// IGNORE_BACKEND_K1: ANY
// ISSUE: KT-61907
// REASON: unexpected red code in K1 (see corresponding diagnostic test)
fun box(): String {
testYield()
return "OK"
}
/* TESTS */
// PTV is in consuming position (yield-case)
fun testYield() {
val arg: UserKlass = UserKlass()
build {
variable = arg
}
}
/* REQUIRED DECLARATIONS */
class Buildee<CT> {
var variable: CT = UserKlass() as CT
}
fun <FT> build(
instructions: Buildee<FT>.() -> Unit
): Buildee<FT> {
return Buildee<FT>().apply(instructions)
}
class UserKlass
@@ -0,0 +1,26 @@
fun box(): String {
testMaterialize()
return "OK"
}
/* TESTS */
// PTV is in producing position (materialize-case)
fun testMaterialize() {
fun consume(arg: Buildee<UserKlass>) {}
build {
consume(it)
}
}
/* REQUIRED DECLARATIONS */
class Buildee<CT>
fun <FT> build(
instructions: (Buildee<FT>) -> Unit
): Buildee<FT> {
return Buildee<FT>().apply(instructions)
}
class UserKlass
@@ -0,0 +1,26 @@
fun box(): String {
testMaterialize()
return "OK"
}
/* TESTS */
// PTV is in producing position (materialize-case)
fun testMaterialize() {
fun consume(arg: Buildee<UserKlass>) {}
build {
consume(this)
}
}
/* 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 @@
fun box(): String {
testMaterialize()
return "OK"
}
/* TESTS */
// PTV is in producing position (materialize-case)
fun testMaterialize() {
build {
this.typeInfoSourcingFunction()
}
}
/* 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,38 @@
fun box(): String {
testMaterializeWithImmutableProperty()
testMaterializeWithMutableProperty()
return "OK"
}
/* TESTS */
// PTV is in producing position (materialize-case) and passed to an immutable extension property
fun testMaterializeWithImmutableProperty() {
build {
this.typeInfoSourcingValue
}
}
// PTV is in producing position (materialize-case) and passed to a mutable extension property
fun testMaterializeWithMutableProperty() {
build {
this.typeInfoSourcingVariable
}
}
/* 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,27 @@
fun box(): String {
testYield()
return "OK"
}
/* TESTS */
// PTV is in consuming position (yield-case)
fun testYield() {
build {
yield(it)
}
}
/* 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,27 @@
fun box(): String {
testYield()
return "OK"
}
/* TESTS */
// PTV is in consuming position (yield-case)
fun testYield() {
build {
it.yield(this)
}
}
/* 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,35 @@
fun box(): String {
testLastStatementReturn()
testExplicitReturn()
return "OK"
}
/* TESTS */
// PTV is returned as a last statement of the builder argument
fun testLastStatementReturn() {
build {
materialize()
}
}
// PTV is returned explicitly
fun testExplicitReturn() {
build {
return@build materialize()
}
}
/* REQUIRED DECLARATIONS */
class Buildee<CT> {
fun materialize(): CT = UserKlass() as CT
}
fun <FT> build(
instructions: Buildee<FT>.() -> UserKlass
): Buildee<FT> {
return Buildee<FT>().apply { this.instructions() }
}
class UserKlass
@@ -0,0 +1,25 @@
fun box(): String {
testExplicitReturn()
return "OK"
}
/* TESTS */
// PTV is returned explicitly
fun testExplicitReturn() {
build {
return@build materialize()
}
}
/* REQUIRED DECLARATIONS */
class Buildee<CT> {
fun materialize(): CT = Unit as CT
}
fun <FT> build(
instructions: Buildee<FT>.() -> Unit
): Buildee<FT> {
return Buildee<FT>().apply { this.instructions() }
}