diff --git a/compiler/testData/codegen/box/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSinks/ExtensionFunctions.kt b/compiler/testData/codegen/box/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSinks/ExtensionFunctions.kt new file mode 100644 index 00000000000..1f2835c105d --- /dev/null +++ b/compiler/testData/codegen/box/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSinks/ExtensionFunctions.kt @@ -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 + +fun Buildee.yield(arg: EFT) {} +fun Buildee.materialize(): EFT = UserKlass() as EFT + +fun build( + instructions: Buildee.() -> Unit +): Buildee { + return Buildee().apply(instructions) +} + +class UserKlass diff --git a/compiler/testData/codegen/box/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSinks/ImmutableExtensionProperties.kt b/compiler/testData/codegen/box/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSinks/ImmutableExtensionProperties.kt new file mode 100644 index 00000000000..60204112774 --- /dev/null +++ b/compiler/testData/codegen/box/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSinks/ImmutableExtensionProperties.kt @@ -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 + +val Buildee.value: EFT get() = UserKlass() as EFT + +fun build( + instructions: Buildee.() -> Unit +): Buildee { + return Buildee().apply(instructions) +} + +class UserKlass diff --git a/compiler/testData/codegen/box/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSinks/ImmutableProperties.kt b/compiler/testData/codegen/box/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSinks/ImmutableProperties.kt new file mode 100644 index 00000000000..6427a086dfc --- /dev/null +++ b/compiler/testData/codegen/box/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSinks/ImmutableProperties.kt @@ -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 { + val value: CT = UserKlass() as CT +} + +fun build( + instructions: Buildee.() -> Unit +): Buildee { + return Buildee().apply(instructions) +} + +class UserKlass diff --git a/compiler/testData/codegen/box/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSinks/MutableExtensionPropertiesMaterializeCase.kt b/compiler/testData/codegen/box/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSinks/MutableExtensionPropertiesMaterializeCase.kt new file mode 100644 index 00000000000..f4529abaeb8 --- /dev/null +++ b/compiler/testData/codegen/box/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSinks/MutableExtensionPropertiesMaterializeCase.kt @@ -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 + +var Buildee.variable: EFT + get() = UserKlass() as EFT + set(value) {} + +fun build( + instructions: Buildee.() -> Unit +): Buildee { + return Buildee().apply(instructions) +} + +class UserKlass diff --git a/compiler/testData/codegen/box/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSinks/MutableExtensionPropertiesYieldCase.kt b/compiler/testData/codegen/box/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSinks/MutableExtensionPropertiesYieldCase.kt new file mode 100644 index 00000000000..6336806b75b --- /dev/null +++ b/compiler/testData/codegen/box/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSinks/MutableExtensionPropertiesYieldCase.kt @@ -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 + +var Buildee.variable: EFT + get() = UserKlass() as EFT + set(value) {} + +fun build( + instructions: Buildee.() -> Unit +): Buildee { + return Buildee().apply(instructions) +} + +class UserKlass diff --git a/compiler/testData/codegen/box/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSinks/MutablePropertiesMaterializeCase.kt b/compiler/testData/codegen/box/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSinks/MutablePropertiesMaterializeCase.kt new file mode 100644 index 00000000000..0d3cbb2e827 --- /dev/null +++ b/compiler/testData/codegen/box/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSinks/MutablePropertiesMaterializeCase.kt @@ -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 { + var variable: CT = UserKlass() as CT +} + +fun build( + instructions: Buildee.() -> Unit +): Buildee { + return Buildee().apply(instructions) +} + +class UserKlass diff --git a/compiler/testData/codegen/box/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSinks/MutablePropertiesYieldCase.kt b/compiler/testData/codegen/box/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSinks/MutablePropertiesYieldCase.kt new file mode 100644 index 00000000000..91d24f418db --- /dev/null +++ b/compiler/testData/codegen/box/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSinks/MutablePropertiesYieldCase.kt @@ -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 { + var variable: CT = UserKlass() as CT +} + +fun build( + instructions: Buildee.() -> Unit +): Buildee { + return Buildee().apply(instructions) +} + +class UserKlass diff --git a/compiler/testData/codegen/box/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSinks/ParametersOfBuilderArguments.kt b/compiler/testData/codegen/box/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSinks/ParametersOfBuilderArguments.kt new file mode 100644 index 00000000000..36efa13fd12 --- /dev/null +++ b/compiler/testData/codegen/box/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSinks/ParametersOfBuilderArguments.kt @@ -0,0 +1,26 @@ +fun box(): String { + testMaterialize() + return "OK" +} + +/* TESTS */ + +// PTV is in producing position (materialize-case) +fun testMaterialize() { + fun consume(arg: Buildee) {} + build { + consume(it) + } +} + +/* REQUIRED DECLARATIONS */ + +class Buildee + +fun build( + instructions: (Buildee) -> Unit +): Buildee { + return Buildee().apply(instructions) +} + +class UserKlass diff --git a/compiler/testData/codegen/box/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSinks/ReceiversOfBuilderArguments.kt b/compiler/testData/codegen/box/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSinks/ReceiversOfBuilderArguments.kt new file mode 100644 index 00000000000..4201932c363 --- /dev/null +++ b/compiler/testData/codegen/box/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSinks/ReceiversOfBuilderArguments.kt @@ -0,0 +1,26 @@ +fun box(): String { + testMaterialize() + return "OK" +} + +/* TESTS */ + +// PTV is in producing position (materialize-case) +fun testMaterialize() { + fun consume(arg: Buildee) {} + build { + consume(this) + } +} + +/* REQUIRED DECLARATIONS */ + +class Buildee + +fun build( + instructions: Buildee.() -> Unit +): Buildee { + return Buildee().apply(instructions) +} + +class UserKlass diff --git a/compiler/testData/codegen/box/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSources/ExtensionFunctions.kt b/compiler/testData/codegen/box/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSources/ExtensionFunctions.kt new file mode 100644 index 00000000000..429bf16e4d5 --- /dev/null +++ b/compiler/testData/codegen/box/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSources/ExtensionFunctions.kt @@ -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 + +fun build( + instructions: Buildee.() -> Unit +): Buildee { + return Buildee().apply(instructions) +} + +class UserKlass + +fun Buildee.typeInfoSourcingFunction() {} diff --git a/compiler/testData/codegen/box/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSources/ExtensionProperties.kt b/compiler/testData/codegen/box/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSources/ExtensionProperties.kt new file mode 100644 index 00000000000..e084b19ae2a --- /dev/null +++ b/compiler/testData/codegen/box/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSources/ExtensionProperties.kt @@ -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 + +fun build( + instructions: Buildee.() -> Unit +): Buildee { + return Buildee().apply(instructions) +} + +class UserKlass + +val Buildee.typeInfoSourcingValue: UserKlass get() = UserKlass() +var Buildee.typeInfoSourcingVariable: UserKlass + get() = UserKlass() + set(value) {} diff --git a/compiler/testData/codegen/box/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSources/ParametersOfBuilderArguments.kt b/compiler/testData/codegen/box/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSources/ParametersOfBuilderArguments.kt new file mode 100644 index 00000000000..24143b1c0a1 --- /dev/null +++ b/compiler/testData/codegen/box/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSources/ParametersOfBuilderArguments.kt @@ -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 { + fun yield(arg: CT) {} +} + +fun build( + instructions: Buildee.(UserKlass) -> Unit +): Buildee { + return Buildee().apply { this.instructions(UserKlass()) } +} + +class UserKlass diff --git a/compiler/testData/codegen/box/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSources/ReceiversOfBuilderArguments.kt b/compiler/testData/codegen/box/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSources/ReceiversOfBuilderArguments.kt new file mode 100644 index 00000000000..d9d2dadd2ad --- /dev/null +++ b/compiler/testData/codegen/box/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSources/ReceiversOfBuilderArguments.kt @@ -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 { + fun yield(arg: CT) {} +} + +fun build( + instructions: UserKlass.(Buildee) -> Unit +): Buildee { + return Buildee().apply { UserKlass().instructions(this) } +} + +class UserKlass diff --git a/compiler/testData/codegen/box/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSources/ReturnTypesOfBuilderParameters.kt b/compiler/testData/codegen/box/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSources/ReturnTypesOfBuilderParameters.kt new file mode 100644 index 00000000000..30f832318e1 --- /dev/null +++ b/compiler/testData/codegen/box/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSources/ReturnTypesOfBuilderParameters.kt @@ -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 { + fun materialize(): CT = UserKlass() as CT +} + +fun build( + instructions: Buildee.() -> UserKlass +): Buildee { + return Buildee().apply { this.instructions() } +} + +class UserKlass diff --git a/compiler/testData/codegen/box/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSources/UnitReturnTypeOfBuilderParametersExplicitReturnCase.kt b/compiler/testData/codegen/box/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSources/UnitReturnTypeOfBuilderParametersExplicitReturnCase.kt new file mode 100644 index 00000000000..3166275701c --- /dev/null +++ b/compiler/testData/codegen/box/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSources/UnitReturnTypeOfBuilderParametersExplicitReturnCase.kt @@ -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 { + fun materialize(): CT = Unit as CT +} + +fun build( + instructions: Buildee.() -> Unit +): Buildee { + return Buildee().apply { this.instructions() } +} diff --git a/compiler/testData/diagnostics/tests/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSinks/ExtensionFunctions.kt b/compiler/testData/diagnostics/tests/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSinks/ExtensionFunctions.kt new file mode 100644 index 00000000000..d059143acd3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSinks/ExtensionFunctions.kt @@ -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) +} + +// 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) +} + +/* REQUIRED DECLARATIONS */ + +class Buildee + +fun Buildee.yield(arg: EFT) {} +fun Buildee.materialize(): EFT = null!! + +fun build( + instructions: Buildee.() -> Unit +): Buildee { + return Buildee().apply(instructions) +} + +class UserKlass diff --git a/compiler/testData/diagnostics/tests/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSinks/ImmutableExtensionProperties.kt b/compiler/testData/diagnostics/tests/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSinks/ImmutableExtensionProperties.kt new file mode 100644 index 00000000000..13e49390a55 --- /dev/null +++ b/compiler/testData/diagnostics/tests/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSinks/ImmutableExtensionProperties.kt @@ -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) +} + +/* REQUIRED DECLARATIONS */ + +class Buildee + +val Buildee.value: EFT get() = null!! + +fun build( + instructions: Buildee.() -> Unit +): Buildee { + return Buildee().apply(instructions) +} + +class UserKlass diff --git a/compiler/testData/diagnostics/tests/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSinks/ImmutableProperties.kt b/compiler/testData/diagnostics/tests/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSinks/ImmutableProperties.kt new file mode 100644 index 00000000000..a2d06ab68ed --- /dev/null +++ b/compiler/testData/diagnostics/tests/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSinks/ImmutableProperties.kt @@ -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) +} + +/* REQUIRED DECLARATIONS */ + +class Buildee { + val value: CT = null!! +} + +fun build( + instructions: Buildee.() -> Unit +): Buildee { + return Buildee().apply(instructions) +} + +class UserKlass diff --git a/compiler/testData/diagnostics/tests/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSinks/MutableExtensionPropertiesMaterializeCase.kt b/compiler/testData/diagnostics/tests/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSinks/MutableExtensionPropertiesMaterializeCase.kt new file mode 100644 index 00000000000..9990e802af8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSinks/MutableExtensionPropertiesMaterializeCase.kt @@ -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) +} + +/* REQUIRED DECLARATIONS */ + +class Buildee + +var Buildee.variable: EFT + get() = null!! + set(value) {} + +fun build( + instructions: Buildee.() -> Unit +): Buildee { + return Buildee().apply(instructions) +} + +class UserKlass diff --git a/compiler/testData/diagnostics/tests/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSinks/MutableExtensionPropertiesYieldCase.fir.kt b/compiler/testData/diagnostics/tests/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSinks/MutableExtensionPropertiesYieldCase.fir.kt new file mode 100644 index 00000000000..40a6a0acaa1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSinks/MutableExtensionPropertiesYieldCase.fir.kt @@ -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) +} + +/* REQUIRED DECLARATIONS */ + +class Buildee + +var Buildee.variable: EFT + get() = null!! + set(value) {} + +fun build( + instructions: Buildee.() -> Unit +): Buildee { + return Buildee().apply(instructions) +} + +class UserKlass diff --git a/compiler/testData/diagnostics/tests/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSinks/MutableExtensionPropertiesYieldCase.kt b/compiler/testData/diagnostics/tests/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSinks/MutableExtensionPropertiesYieldCase.kt new file mode 100644 index 00000000000..449ca6d1e5b --- /dev/null +++ b/compiler/testData/diagnostics/tests/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSinks/MutableExtensionPropertiesYieldCase.kt @@ -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) +} + +/* REQUIRED DECLARATIONS */ + +class Buildee + +var Buildee.variable: EFT + get() = null!! + set(value) {} + +fun build( + instructions: Buildee.() -> Unit +): Buildee { + return Buildee().apply(instructions) +} + +class UserKlass diff --git a/compiler/testData/diagnostics/tests/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSinks/MutablePropertiesMaterializeCase.kt b/compiler/testData/diagnostics/tests/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSinks/MutablePropertiesMaterializeCase.kt new file mode 100644 index 00000000000..ba53f3c8f7f --- /dev/null +++ b/compiler/testData/diagnostics/tests/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSinks/MutablePropertiesMaterializeCase.kt @@ -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) +} + +/* REQUIRED DECLARATIONS */ + +class Buildee { + var variable: CT = null!! +} + +fun build( + instructions: Buildee.() -> Unit +): Buildee { + return Buildee().apply(instructions) +} + +class UserKlass diff --git a/compiler/testData/diagnostics/tests/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSinks/MutablePropertiesYieldCase.fir.kt b/compiler/testData/diagnostics/tests/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSinks/MutablePropertiesYieldCase.fir.kt new file mode 100644 index 00000000000..c81a95feb9e --- /dev/null +++ b/compiler/testData/diagnostics/tests/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSinks/MutablePropertiesYieldCase.fir.kt @@ -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) +} + +/* REQUIRED DECLARATIONS */ + +class Buildee { + var variable: CT = null!! +} + +fun build( + instructions: Buildee.() -> Unit +): Buildee { + return Buildee().apply(instructions) +} + +class UserKlass diff --git a/compiler/testData/diagnostics/tests/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSinks/MutablePropertiesYieldCase.kt b/compiler/testData/diagnostics/tests/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSinks/MutablePropertiesYieldCase.kt new file mode 100644 index 00000000000..38f27cc0053 --- /dev/null +++ b/compiler/testData/diagnostics/tests/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSinks/MutablePropertiesYieldCase.kt @@ -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) +} + +/* REQUIRED DECLARATIONS */ + +class Buildee { + var variable: CT = null!! +} + +fun build( + instructions: Buildee.() -> Unit +): Buildee { + return Buildee().apply(instructions) +} + +class UserKlass diff --git a/compiler/testData/diagnostics/tests/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSinks/ParametersOfBuilderArguments.kt b/compiler/testData/diagnostics/tests/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSinks/ParametersOfBuilderArguments.kt new file mode 100644 index 00000000000..9a250960ca6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSinks/ParametersOfBuilderArguments.kt @@ -0,0 +1,27 @@ +// FIR_IDENTICAL +// CHECK_TYPE_WITH_EXACT + +/* TESTS */ + +// PTV is in producing position (materialize-case) +fun testMaterialize() { + fun consume(arg: Buildee) {} + 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) +} + +/* REQUIRED DECLARATIONS */ + +class Buildee + +fun build( + instructions: (Buildee) -> Unit +): Buildee { + return Buildee().apply(instructions) +} + +class UserKlass diff --git a/compiler/testData/diagnostics/tests/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSinks/ReceiversOfBuilderArguments.kt b/compiler/testData/diagnostics/tests/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSinks/ReceiversOfBuilderArguments.kt new file mode 100644 index 00000000000..0c2a6600b2e --- /dev/null +++ b/compiler/testData/diagnostics/tests/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSinks/ReceiversOfBuilderArguments.kt @@ -0,0 +1,27 @@ +// FIR_IDENTICAL +// CHECK_TYPE_WITH_EXACT + +/* TESTS */ + +// PTV is in producing position (materialize-case) +fun testMaterialize() { + fun consume(arg: Buildee) {} + 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) +} + +/* REQUIRED DECLARATIONS */ + +class Buildee + +fun build( + instructions: Buildee.() -> Unit +): Buildee { + return Buildee().apply(instructions) +} + +class UserKlass diff --git a/compiler/testData/diagnostics/tests/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSources/ExtensionFunctions.kt b/compiler/testData/diagnostics/tests/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSources/ExtensionFunctions.kt new file mode 100644 index 00000000000..f998ba9dfca --- /dev/null +++ b/compiler/testData/diagnostics/tests/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSources/ExtensionFunctions.kt @@ -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) +} + +/* REQUIRED DECLARATIONS */ + +class Buildee + +fun build( + instructions: Buildee.() -> Unit +): Buildee { + return Buildee().apply(instructions) +} + +class UserKlass + +fun Buildee.typeInfoSourcingFunction() {} diff --git a/compiler/testData/diagnostics/tests/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSources/ExtensionProperties.kt b/compiler/testData/diagnostics/tests/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSources/ExtensionProperties.kt new file mode 100644 index 00000000000..ca11e05e204 --- /dev/null +++ b/compiler/testData/diagnostics/tests/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSources/ExtensionProperties.kt @@ -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) +} + +// 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) +} + +/* REQUIRED DECLARATIONS */ + +class Buildee + +fun build( + instructions: Buildee.() -> Unit +): Buildee { + return Buildee().apply(instructions) +} + +class UserKlass + +val Buildee.typeInfoSourcingValue: UserKlass get() = UserKlass() +var Buildee.typeInfoSourcingVariable: UserKlass + get() = UserKlass() + set(value) {} diff --git a/compiler/testData/diagnostics/tests/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSources/ParametersOfBuilderArguments.kt b/compiler/testData/diagnostics/tests/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSources/ParametersOfBuilderArguments.kt new file mode 100644 index 00000000000..ae12d46eb6c --- /dev/null +++ b/compiler/testData/diagnostics/tests/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSources/ParametersOfBuilderArguments.kt @@ -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) +} + +/* REQUIRED DECLARATIONS */ + +class Buildee { + fun yield(arg: CT) {} +} + +fun build( + instructions: Buildee.(UserKlass) -> Unit +): Buildee { + return Buildee().apply { this.instructions(UserKlass()) } +} + +class UserKlass diff --git a/compiler/testData/diagnostics/tests/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSources/ReceiversOfBuilderArguments.kt b/compiler/testData/diagnostics/tests/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSources/ReceiversOfBuilderArguments.kt new file mode 100644 index 00000000000..1647353c290 --- /dev/null +++ b/compiler/testData/diagnostics/tests/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSources/ReceiversOfBuilderArguments.kt @@ -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) +} + +/* REQUIRED DECLARATIONS */ + +class Buildee { + fun yield(arg: CT) {} +} + +fun build( + instructions: UserKlass.(Buildee) -> Unit +): Buildee { + return Buildee().apply { UserKlass().instructions(this) } +} + +class UserKlass diff --git a/compiler/testData/diagnostics/tests/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSources/ReturnTypesOfBuilderParameters.kt b/compiler/testData/diagnostics/tests/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSources/ReturnTypesOfBuilderParameters.kt new file mode 100644 index 00000000000..207b7e6bfe8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSources/ReturnTypesOfBuilderParameters.kt @@ -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) +} + +// 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) +} + +/* REQUIRED DECLARATIONS */ + +class Buildee { + fun materialize(): CT = null!! +} + +fun build( + instructions: Buildee.() -> UserKlass +): Buildee { + return Buildee().apply { this.instructions() } +} + +class UserKlass diff --git a/compiler/testData/diagnostics/tests/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSources/UnitReturnTypeOfBuilderParametersExplicitReturnCase.kt b/compiler/testData/diagnostics/tests/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSources/UnitReturnTypeOfBuilderParametersExplicitReturnCase.kt new file mode 100644 index 00000000000..1d13d85cb05 --- /dev/null +++ b/compiler/testData/diagnostics/tests/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSources/UnitReturnTypeOfBuilderParametersExplicitReturnCase.kt @@ -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) +} + +/* REQUIRED DECLARATIONS */ + +class Buildee { + fun materialize(): CT = null!! +} + +fun build( + instructions: Buildee.() -> Unit +): Buildee { + return Buildee().apply { this.instructions() } +} diff --git a/compiler/testData/diagnostics/tests/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSources/UnitReturnTypeOfBuilderParametersLastStatementReturnCase.fir.kt b/compiler/testData/diagnostics/tests/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSources/UnitReturnTypeOfBuilderParametersLastStatementReturnCase.fir.kt new file mode 100644 index 00000000000..df38568b57c --- /dev/null +++ b/compiler/testData/diagnostics/tests/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSources/UnitReturnTypeOfBuilderParametersLastStatementReturnCase.fir.kt @@ -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 = 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>(buildee) +} + +/* REQUIRED DECLARATIONS */ + +class Buildee { + fun materialize(): CT = null!! +} + +fun build( + instructions: Buildee.() -> Unit +): Buildee { + return Buildee().apply { this.instructions() } +} diff --git a/compiler/testData/diagnostics/tests/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSources/UnitReturnTypeOfBuilderParametersLastStatementReturnCase.kt b/compiler/testData/diagnostics/tests/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSources/UnitReturnTypeOfBuilderParametersLastStatementReturnCase.kt new file mode 100644 index 00000000000..734856bc102 --- /dev/null +++ b/compiler/testData/diagnostics/tests/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/typeInfoSources/UnitReturnTypeOfBuilderParametersLastStatementReturnCase.kt @@ -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 = 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) +} + +/* REQUIRED DECLARATIONS */ + +class Buildee { + fun materialize(): CT = null!! +} + +fun build( + instructions: Buildee.() -> Unit +): Buildee { + return Buildee().apply { this.instructions() } +}