diff --git a/compiler/testData/codegen/box/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/sourceSinkFeedContexts/ByAssignmentToALocalVariableMaterializeCase.kt b/compiler/testData/codegen/box/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/sourceSinkFeedContexts/ByAssignmentToALocalVariableMaterializeCase.kt new file mode 100644 index 00000000000..477a58324c2 --- /dev/null +++ b/compiler/testData/codegen/box/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/sourceSinkFeedContexts/ByAssignmentToALocalVariableMaterializeCase.kt @@ -0,0 +1,29 @@ +fun box(): String { + testMaterialize() + return "OK" +} + +/* TESTS */ + +// PTV is in producing position (materialize-case) +fun testMaterialize() { + val arg: UserKlass = UserKlass() + build { + var temp = arg + temp = materialize() + } +} + +/* REQUIRED DECLARATIONS */ + +class Buildee { + fun materialize(): 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/sourceSinkFeedContexts/ByAssignmentToALocalVariableYieldCase.kt b/compiler/testData/codegen/box/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/sourceSinkFeedContexts/ByAssignmentToALocalVariableYieldCase.kt new file mode 100644 index 00000000000..81015a1e457 --- /dev/null +++ b/compiler/testData/codegen/box/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/sourceSinkFeedContexts/ByAssignmentToALocalVariableYieldCase.kt @@ -0,0 +1,33 @@ +// IGNORE_BACKEND_K1: ANY +// ISSUE: KT-63816 +// 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 { + var temp = materialize() + temp = arg + } +} + +/* REQUIRED DECLARATIONS */ + +class Buildee { + fun materialize(): 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/sourceSinkFeedContexts/InsideLocalClass.kt b/compiler/testData/codegen/box/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/sourceSinkFeedContexts/InsideLocalClass.kt new file mode 100644 index 00000000000..060e8bc46eb --- /dev/null +++ b/compiler/testData/codegen/box/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/sourceSinkFeedContexts/InsideLocalClass.kt @@ -0,0 +1,46 @@ +fun box(): String { + testYield() + testMaterialize() + return "OK" +} + +/* TESTS */ + +// PTV is in consuming position (yield-case) +fun testYield() { + val arg: UserKlass = UserKlass() + build { + class LocalClass { + init { + yield(arg) + } + } + } +} + +// PTV is in producing position (materialize-case) +fun testMaterialize() { + fun consume(arg: UserKlass) {} + build { + class LocalClass { + init { + consume(materialize()) + } + } + } +} + +/* REQUIRED DECLARATIONS */ + +class Buildee { + fun yield(arg: CT) {} + fun materialize(): 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/sourceSinkFeedContexts/ThroughGenericFunctionCall.kt b/compiler/testData/codegen/box/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/sourceSinkFeedContexts/ThroughGenericFunctionCall.kt new file mode 100644 index 00000000000..da19dc460c2 --- /dev/null +++ b/compiler/testData/codegen/box/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/sourceSinkFeedContexts/ThroughGenericFunctionCall.kt @@ -0,0 +1,40 @@ +fun box(): String { + testYield() + testMaterialize() + return "OK" +} + +/* TESTS */ + +// PTV is in consuming position (yield-case) +fun testYield() { + val arg: UserKlass = UserKlass() + build { + yield(id(arg)) + } +} + +// PTV is in producing position (materialize-case) +fun testMaterialize() { + fun consume(arg: UserKlass) {} + build { + consume(id(materialize())) + } +} + +/* REQUIRED DECLARATIONS */ + +class Buildee { + fun yield(arg: CT) {} + fun materialize(): CT = UserKlass() as CT +} + +fun build( + instructions: Buildee.() -> Unit +): Buildee { + return Buildee().apply(instructions) +} + +class UserKlass + +fun id(arg: T): T = arg diff --git a/compiler/testData/diagnostics/tests/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/sourceSinkFeedContexts/ByAssignmentToALocalVariableMaterializeCase.kt b/compiler/testData/diagnostics/tests/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/sourceSinkFeedContexts/ByAssignmentToALocalVariableMaterializeCase.kt new file mode 100644 index 00000000000..e86aa77e6e1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/sourceSinkFeedContexts/ByAssignmentToALocalVariableMaterializeCase.kt @@ -0,0 +1,31 @@ +// FIR_IDENTICAL +// CHECK_TYPE_WITH_EXACT +// DIAGNOSTICS: -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE + +/* TESTS */ + +// PTV is in producing position (materialize-case) +fun testMaterialize() { + val arg: UserKlass = UserKlass() + val buildee = build { + var temp = arg + temp = 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(instructions) +} + +class UserKlass diff --git a/compiler/testData/diagnostics/tests/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/sourceSinkFeedContexts/ByAssignmentToALocalVariableYieldCase.fir.kt b/compiler/testData/diagnostics/tests/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/sourceSinkFeedContexts/ByAssignmentToALocalVariableYieldCase.fir.kt new file mode 100644 index 00000000000..dbc4a31d627 --- /dev/null +++ b/compiler/testData/diagnostics/tests/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/sourceSinkFeedContexts/ByAssignmentToALocalVariableYieldCase.fir.kt @@ -0,0 +1,33 @@ +// CHECK_TYPE_WITH_EXACT +// DIAGNOSTICS: -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE + +// ISSUE: KT-63816 +// REASON: unexpected red code in K1 + +/* TESTS */ + +// PTV is in consuming position (yield-case) +fun testYield() { + val arg: UserKlass = UserKlass() + val buildee = build { + var temp = materialize() + temp = 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 { + fun materialize(): 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/sourceSinkFeedContexts/ByAssignmentToALocalVariableYieldCase.kt b/compiler/testData/diagnostics/tests/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/sourceSinkFeedContexts/ByAssignmentToALocalVariableYieldCase.kt new file mode 100644 index 00000000000..460cc668004 --- /dev/null +++ b/compiler/testData/diagnostics/tests/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/sourceSinkFeedContexts/ByAssignmentToALocalVariableYieldCase.kt @@ -0,0 +1,33 @@ +// CHECK_TYPE_WITH_EXACT +// DIAGNOSTICS: -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE + +// ISSUE: KT-63816 +// REASON: unexpected red code in K1 + +/* TESTS */ + +// PTV is in consuming position (yield-case) +fun testYield() { + val arg: UserKlass = UserKlass() + val buildee = build { + var temp = materialize() + temp = 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 { + fun materialize(): 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/sourceSinkFeedContexts/InsideLocalClass.kt b/compiler/testData/diagnostics/tests/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/sourceSinkFeedContexts/InsideLocalClass.kt new file mode 100644 index 00000000000..6057fc8e64c --- /dev/null +++ b/compiler/testData/diagnostics/tests/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/sourceSinkFeedContexts/InsideLocalClass.kt @@ -0,0 +1,49 @@ +// FIR_IDENTICAL +// CHECK_TYPE_WITH_EXACT + +/* TESTS */ + +// PTV is in consuming position (yield-case) +fun testYield() { + val arg: UserKlass = UserKlass() + val buildee = build { + class LocalClass { + init { + 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 { + class LocalClass { + init { + 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 yield(arg: CT) {} + fun materialize(): 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/sourceSinkFeedContexts/ThroughGenericFunctionCall.kt b/compiler/testData/diagnostics/tests/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/sourceSinkFeedContexts/ThroughGenericFunctionCall.kt new file mode 100644 index 00000000000..c4907b823c9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/builderInference/oneParameter/oneTypeVariable/oneTypeInfoOrigin/sourceSinkFeedContexts/ThroughGenericFunctionCall.kt @@ -0,0 +1,43 @@ +// FIR_IDENTICAL +// CHECK_TYPE_WITH_EXACT + +/* TESTS */ + +// PTV is in consuming position (yield-case) +fun testYield() { + val arg: UserKlass = UserKlass() + val buildee = build { + yield(id(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(id(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 yield(arg: CT) {} + fun materialize(): CT = null!! +} + +fun build( + instructions: Buildee.() -> Unit +): Buildee { + return Buildee().apply(instructions) +} + +class UserKlass + +fun id(arg: T): T = arg