From 4671a9612af5c5fdadbdffb89c2393f2c32059c2 Mon Sep 17 00:00:00 2001 From: Stanislav Ruban Date: Sat, 2 Dec 2023 15:28:59 +0100 Subject: [PATCH] [tests] Add test data for KT-61310 --- .../box/builderInference/issues/kt61310.kt | 31 +++++++++++++++++++ .../builderInference/issues/kt61310.fir.kt | 30 ++++++++++++++++++ .../tests/builderInference/issues/kt61310.kt | 30 ++++++++++++++++++ 3 files changed, 91 insertions(+) create mode 100644 compiler/testData/codegen/box/builderInference/issues/kt61310.kt create mode 100644 compiler/testData/diagnostics/tests/builderInference/issues/kt61310.fir.kt create mode 100644 compiler/testData/diagnostics/tests/builderInference/issues/kt61310.kt diff --git a/compiler/testData/codegen/box/builderInference/issues/kt61310.kt b/compiler/testData/codegen/box/builderInference/issues/kt61310.kt new file mode 100644 index 00000000000..6562ae7ef76 --- /dev/null +++ b/compiler/testData/codegen/box/builderInference/issues/kt61310.kt @@ -0,0 +1,31 @@ +// ISSUE: KT-61310 + +// IGNORE_LIGHT_ANALYSIS +// IGNORE_BACKEND_K2: ANY +// REASON: red code (see corresponding diagnostic test) + +fun box(): String { + build { + if (true) { + setTypeVariable(GenericBox()) + } else { + setTypeVariable(GenericBox()) + } + } + return "OK" +} + + + + +class TargetType +class GenericBox + +class Buildee { + fun setTypeVariable(value: TV) { storage = value } + private var storage: TV = GenericBox() as TV +} + +fun build(instructions: Buildee.() -> Unit): Buildee { + return Buildee().apply(instructions) +} diff --git a/compiler/testData/diagnostics/tests/builderInference/issues/kt61310.fir.kt b/compiler/testData/diagnostics/tests/builderInference/issues/kt61310.fir.kt new file mode 100644 index 00000000000..755d7b688d1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/builderInference/issues/kt61310.fir.kt @@ -0,0 +1,30 @@ +// ISSUE: KT-61310 +// CHECK_TYPE_WITH_EXACT + +fun test() { + val buildee = build { + if (true) { + setTypeVariable(GenericBox()) + } else { + setTypeVariable(GenericBox()) + } + } + // 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 GenericBox + +class Buildee { + fun setTypeVariable(value: TV) { storage = value } + private var storage: TV = null!! +} + +fun build(instructions: Buildee.() -> Unit): Buildee { + return Buildee().apply(instructions) +} diff --git a/compiler/testData/diagnostics/tests/builderInference/issues/kt61310.kt b/compiler/testData/diagnostics/tests/builderInference/issues/kt61310.kt new file mode 100644 index 00000000000..efa1c96e178 --- /dev/null +++ b/compiler/testData/diagnostics/tests/builderInference/issues/kt61310.kt @@ -0,0 +1,30 @@ +// ISSUE: KT-61310 +// CHECK_TYPE_WITH_EXACT + +fun test() { + val buildee = build { + if (true) { + setTypeVariable(GenericBox()) + } else { + setTypeVariable(GenericBox()) + } + } + // 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 GenericBox + +class Buildee { + fun setTypeVariable(value: TV) { storage = value } + private var storage: TV = null!! +} + +fun build(instructions: Buildee.() -> Unit): Buildee { + return Buildee().apply(instructions) +}