From 222648615227ad2caa56d4010ef0ed443aed8429 Mon Sep 17 00:00:00 2001 From: Stanislav Ruban Date: Sat, 2 Dec 2023 15:27:07 +0100 Subject: [PATCH] [tests] Add test data for KT-56949 --- .../box/builderInference/issues/kt56949.kt | 34 +++++++++++++++++++ .../builderInference/issues/kt56949.fir.kt | 30 ++++++++++++++++ .../tests/builderInference/issues/kt56949.kt | 30 ++++++++++++++++ 3 files changed, 94 insertions(+) create mode 100644 compiler/testData/codegen/box/builderInference/issues/kt56949.kt create mode 100644 compiler/testData/diagnostics/tests/builderInference/issues/kt56949.fir.kt create mode 100644 compiler/testData/diagnostics/tests/builderInference/issues/kt56949.kt diff --git a/compiler/testData/codegen/box/builderInference/issues/kt56949.kt b/compiler/testData/codegen/box/builderInference/issues/kt56949.kt new file mode 100644 index 00000000000..cb80c3ac8d9 --- /dev/null +++ b/compiler/testData/codegen/box/builderInference/issues/kt56949.kt @@ -0,0 +1,34 @@ +// ISSUE: KT-56949 + +// 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 @ Kt56949Kt$box$1.invoke) + +fun box(): String { + build { + setTypeVariable(TargetType()) + consumeDifferentTypeSubtype(getTypeVariable()) + } + return "OK" +} + + + + +class TargetType +class DifferentType + +fun consumeDifferentTypeSubtype(value: T) {} + +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/kt56949.fir.kt b/compiler/testData/diagnostics/tests/builderInference/issues/kt56949.fir.kt new file mode 100644 index 00000000000..42fd1be2c67 --- /dev/null +++ b/compiler/testData/diagnostics/tests/builderInference/issues/kt56949.fir.kt @@ -0,0 +1,30 @@ +// ISSUE: KT-56949 +// CHECK_TYPE_WITH_EXACT + +fun test() { + val buildee = build { + setTypeVariable(TargetType()) + consumeDifferentTypeSubtype(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 DifferentType> consumeDifferentTypeSubtype(value: T) {} + +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/kt56949.kt b/compiler/testData/diagnostics/tests/builderInference/issues/kt56949.kt new file mode 100644 index 00000000000..62dc9184312 --- /dev/null +++ b/compiler/testData/diagnostics/tests/builderInference/issues/kt56949.kt @@ -0,0 +1,30 @@ +// ISSUE: KT-56949 +// CHECK_TYPE_WITH_EXACT + +fun test() { + val buildee = build { + setTypeVariable(TargetType()) + consumeDifferentTypeSubtype(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 DifferentType> consumeDifferentTypeSubtype(value: T) {} + +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) +}