From 126022a80d63c4c0a171af1bc03a475ae16b92fe Mon Sep 17 00:00:00 2001 From: Stanislav Ruban Date: Sat, 2 Dec 2023 15:25:19 +0100 Subject: [PATCH] [tests] Add test data for KT-53740 --- .../box/builderInference/issues/kt53740a.kt | 45 ++++++++++++++++ .../box/builderInference/issues/kt53740b.kt | 53 +++++++++++++++++++ .../builderInference/issues/kt53740a.fir.kt | 37 +++++++++++++ .../tests/builderInference/issues/kt53740a.kt | 37 +++++++++++++ .../builderInference/issues/kt53740b.fir.kt | 45 ++++++++++++++++ .../tests/builderInference/issues/kt53740b.kt | 45 ++++++++++++++++ 6 files changed, 262 insertions(+) create mode 100644 compiler/testData/codegen/box/builderInference/issues/kt53740a.kt create mode 100644 compiler/testData/codegen/box/builderInference/issues/kt53740b.kt create mode 100644 compiler/testData/diagnostics/tests/builderInference/issues/kt53740a.fir.kt create mode 100644 compiler/testData/diagnostics/tests/builderInference/issues/kt53740a.kt create mode 100644 compiler/testData/diagnostics/tests/builderInference/issues/kt53740b.fir.kt create mode 100644 compiler/testData/diagnostics/tests/builderInference/issues/kt53740b.kt diff --git a/compiler/testData/codegen/box/builderInference/issues/kt53740a.kt b/compiler/testData/codegen/box/builderInference/issues/kt53740a.kt new file mode 100644 index 00000000000..121c7d0787a --- /dev/null +++ b/compiler/testData/codegen/box/builderInference/issues/kt53740a.kt @@ -0,0 +1,45 @@ +// ISSUE: KT-53740 + +// IGNORE_LIGHT_ANALYSIS +// IGNORE_BACKEND_K1: ANY +// REASON: red code (see corresponding diagnostic test) + +// IGNORE_BACKEND_K2: JVM_IR, WASM +// REASON: run-time failure (java.lang.ClassCastException: TargetType cannot be cast to DifferentType @ Kt53740aKt$box$2.invoke) + +fun box(): String { + parallelBuild( + { + setTypeVariable(TargetType()) + }, + { + consumeDifferentType(getTypeVariable()) + } + ) + return "OK" +} + + + + +class TargetType +class DifferentType + +fun consumeDifferentType(value: DifferentType) {} + +class Buildee { + fun setTypeVariable(value: TV) { storage = value } + fun getTypeVariable(): TV = storage + private var storage: TV = TargetType() as TV +} + +fun parallelBuild( + instructionsA: Buildee.(PTV) -> Unit, + instructionsB: Buildee.(PTV) -> Unit +): Buildee { + val value = TargetType() as PTV + return Buildee().apply { + instructionsA(value) + instructionsB(value) + } +} diff --git a/compiler/testData/codegen/box/builderInference/issues/kt53740b.kt b/compiler/testData/codegen/box/builderInference/issues/kt53740b.kt new file mode 100644 index 00000000000..44bc436d773 --- /dev/null +++ b/compiler/testData/codegen/box/builderInference/issues/kt53740b.kt @@ -0,0 +1,53 @@ +// ISSUE: KT-53740 + +// IGNORE_LIGHT_ANALYSIS +// IGNORE_BACKEND_K1: ANY +// REASON: red code (see corresponding diagnostic test) + +// IGNORE_BACKEND_K2: JVM_IR, WASM +// REASON: run-time failure (java.lang.ClassCastException: TargetType cannot be cast to DifferentType @ Kt53740bKt$box$2.invoke) + +fun box(): String { + parallelInOutBuild( + { + setInProjectedTypeVariable(TargetType()) + }, + { + consumeDifferentType(getOutProjectedTypeVariable()) + } + ) + return "OK" +} + + + + +class TargetType +class DifferentType + +fun consumeDifferentType(value: DifferentType) {} + +class Buildee { + fun setTypeVariable(value: TV) { storage = value } + fun getTypeVariable(): TV = storage + private var storage: TV = TargetType() as TV +} + +class OutBuildee(private val buildee: Buildee) { + fun getOutProjectedTypeVariable(): OTV = buildee.getTypeVariable() +} + +class InBuildee(private val buildee: Buildee) { + fun setInProjectedTypeVariable(value: ITV) { buildee.setTypeVariable(value) } +} + +fun parallelInOutBuild( + inProjectedInstructions: InBuildee.(PTV) -> Unit, + outProjectedInstructions: OutBuildee.(PTV) -> Unit +): Buildee { + val value = TargetType() as PTV + return Buildee().apply { + InBuildee(this).inProjectedInstructions(value) + OutBuildee(this).outProjectedInstructions(value) + } +} diff --git a/compiler/testData/diagnostics/tests/builderInference/issues/kt53740a.fir.kt b/compiler/testData/diagnostics/tests/builderInference/issues/kt53740a.fir.kt new file mode 100644 index 00000000000..f02069d58d9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/builderInference/issues/kt53740a.fir.kt @@ -0,0 +1,37 @@ +// ISSUE: KT-53740 +// CHECK_TYPE_WITH_EXACT + +fun test() { + val buildee = parallelBuild( + { + setTypeVariable(TargetType()) + }, + { + consumeDifferentType(getTypeVariable()) + } + ) + // 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) +} + + + + +class TargetType +class DifferentType + +fun consumeDifferentType(value: DifferentType) {} + +class Buildee { + fun setTypeVariable(value: TV) { storage = value } + fun getTypeVariable(): TV = storage + private var storage: TV = null!! +} + +fun parallelBuild( + instructionsA: Buildee.(PTV) -> Unit, + instructionsB: Buildee.(PTV) -> Unit +): Buildee { + return null!! +} diff --git a/compiler/testData/diagnostics/tests/builderInference/issues/kt53740a.kt b/compiler/testData/diagnostics/tests/builderInference/issues/kt53740a.kt new file mode 100644 index 00000000000..aae593b8036 --- /dev/null +++ b/compiler/testData/diagnostics/tests/builderInference/issues/kt53740a.kt @@ -0,0 +1,37 @@ +// ISSUE: KT-53740 +// CHECK_TYPE_WITH_EXACT + +fun test() { + val buildee = parallelBuild( + { + setTypeVariable(TargetType()) + }, + { + consumeDifferentType(getTypeVariable()) + } + ) + // 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"), TYPE_MISMATCH("Buildee; Buildee")!>buildee) +} + + + + +class TargetType +class DifferentType + +fun consumeDifferentType(value: DifferentType) {} + +class Buildee { + fun setTypeVariable(value: TV) { storage = value } + fun getTypeVariable(): TV = storage + private var storage: TV = null!! +} + +fun parallelBuild( + instructionsA: Buildee.(PTV) -> Unit, + instructionsB: Buildee.(PTV) -> Unit +): Buildee { + return null!! +} diff --git a/compiler/testData/diagnostics/tests/builderInference/issues/kt53740b.fir.kt b/compiler/testData/diagnostics/tests/builderInference/issues/kt53740b.fir.kt new file mode 100644 index 00000000000..d049158b2ac --- /dev/null +++ b/compiler/testData/diagnostics/tests/builderInference/issues/kt53740b.fir.kt @@ -0,0 +1,45 @@ +// ISSUE: KT-53740 +// CHECK_TYPE_WITH_EXACT + +fun test() { + val buildee = parallelInOutBuild( + { + setInProjectedTypeVariable(TargetType()) + }, + { + consumeDifferentType(getOutProjectedTypeVariable()) + } + ) + // 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) +} + + + + +class TargetType +class DifferentType + +fun consumeDifferentType(value: DifferentType) {} + +class Buildee { + fun setTypeVariable(value: TV) { storage = value } + fun getTypeVariable(): TV = storage + private var storage: TV = null!! +} + +class OutBuildee(private val buildee: Buildee) { + fun getOutProjectedTypeVariable(): OTV = buildee.getTypeVariable() +} + +class InBuildee(private val buildee: Buildee) { + fun setInProjectedTypeVariable(value: ITV) { buildee.setTypeVariable(value) } +} + +fun parallelInOutBuild( + inProjectedInstructions: InBuildee.(PTV) -> Unit, + outProjectedInstructions: OutBuildee.(PTV) -> Unit +): Buildee { + return null!! +} diff --git a/compiler/testData/diagnostics/tests/builderInference/issues/kt53740b.kt b/compiler/testData/diagnostics/tests/builderInference/issues/kt53740b.kt new file mode 100644 index 00000000000..70f4916f864 --- /dev/null +++ b/compiler/testData/diagnostics/tests/builderInference/issues/kt53740b.kt @@ -0,0 +1,45 @@ +// ISSUE: KT-53740 +// CHECK_TYPE_WITH_EXACT + +fun test() { + val buildee = parallelInOutBuild( + { + setInProjectedTypeVariable(TargetType()) + }, + { + consumeDifferentType(getOutProjectedTypeVariable()) + } + ) + // 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"), TYPE_MISMATCH("Buildee; Buildee")!>buildee) +} + + + + +class TargetType +class DifferentType + +fun consumeDifferentType(value: DifferentType) {} + +class Buildee { + fun setTypeVariable(value: TV) { storage = value } + fun getTypeVariable(): TV = storage + private var storage: TV = null!! +} + +class OutBuildee(private val buildee: Buildee) { + fun getOutProjectedTypeVariable(): OTV = buildee.getTypeVariable() +} + +class InBuildee(private val buildee: Buildee) { + fun setInProjectedTypeVariable(value: ITV) { buildee.setTypeVariable(value) } +} + +fun parallelInOutBuild( + inProjectedInstructions: InBuildee.(PTV) -> Unit, + outProjectedInstructions: OutBuildee.(PTV) -> Unit +): Buildee { + return null!! +}