From de8f0c157eda57f4062159a3a73712f9894d07c7 Mon Sep 17 00:00:00 2001 From: Stanislav Ruban Date: Thu, 30 Nov 2023 22:03:32 +0100 Subject: [PATCH] [tests] Add test data for KT-50453 --- .../box/builderInference/issues/kt50453.kt | 35 +++++++++++++++++++ .../builderInference/issues/kt50453.fir.kt | 31 ++++++++++++++++ .../tests/builderInference/issues/kt50453.kt | 31 ++++++++++++++++ 3 files changed, 97 insertions(+) create mode 100644 compiler/testData/codegen/box/builderInference/issues/kt50453.kt create mode 100644 compiler/testData/diagnostics/tests/builderInference/issues/kt50453.fir.kt create mode 100644 compiler/testData/diagnostics/tests/builderInference/issues/kt50453.kt diff --git a/compiler/testData/codegen/box/builderInference/issues/kt50453.kt b/compiler/testData/codegen/box/builderInference/issues/kt50453.kt new file mode 100644 index 00000000000..a7281c6b680 --- /dev/null +++ b/compiler/testData/codegen/box/builderInference/issues/kt50453.kt @@ -0,0 +1,35 @@ +// ISSUE: KT-50453 + +// 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 @ Kt50453Kt$box$1.invoke) + +fun box(): String { + build { + setTypeVariable(TargetType()) + consume(getTypeVariable()) + } + return "OK" +} + + + + +class TargetType +class DifferentType + +fun consume(value: Any) {} +fun consume(value: DifferentType) {} + +class Buildee { + fun setTypeVariable(value: TV) { storage = value } + fun getTypeVariable(): TV = storage + private var storage: TV = TargetType() as TV +} + +fun build(instructions: Buildee.() -> Unit): Buildee { + return Buildee().apply(instructions) +} diff --git a/compiler/testData/diagnostics/tests/builderInference/issues/kt50453.fir.kt b/compiler/testData/diagnostics/tests/builderInference/issues/kt50453.fir.kt new file mode 100644 index 00000000000..9136a144736 --- /dev/null +++ b/compiler/testData/diagnostics/tests/builderInference/issues/kt50453.fir.kt @@ -0,0 +1,31 @@ +// ISSUE: KT-50453 +// CHECK_TYPE_WITH_EXACT + +fun test() { + val buildee = build { + setTypeVariable(TargetType()) + consume(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) +} + + + + +class TargetType +class DifferentType + +fun consume(value: Any) {} +fun consume(value: DifferentType) {} + +class Buildee { + fun setTypeVariable(value: TV) { storage = value } + fun getTypeVariable(): TV = storage + private var storage: TV = null!! +} + +fun build(instructions: Buildee.() -> Unit): Buildee { + return Buildee().apply(instructions) +} diff --git a/compiler/testData/diagnostics/tests/builderInference/issues/kt50453.kt b/compiler/testData/diagnostics/tests/builderInference/issues/kt50453.kt new file mode 100644 index 00000000000..19236a80570 --- /dev/null +++ b/compiler/testData/diagnostics/tests/builderInference/issues/kt50453.kt @@ -0,0 +1,31 @@ +// ISSUE: KT-50453 +// CHECK_TYPE_WITH_EXACT + +fun test() { + val buildee = build { + setTypeVariable(TargetType()) + consume(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) +} + + + + +class TargetType +class DifferentType + +fun consume(value: Any) {} +fun consume(value: DifferentType) {} + +class Buildee { + fun setTypeVariable(value: TV) { storage = value } + fun getTypeVariable(): TV = storage + private var storage: TV = null!! +} + +fun build(instructions: Buildee.() -> Unit): Buildee { + return Buildee().apply(instructions) +}