From e5642d83aa770cbe001749622e522d63b875e772 Mon Sep 17 00:00:00 2001 From: Stanislav Ruban Date: Sat, 2 Dec 2023 15:28:13 +0100 Subject: [PATCH] [tests] Add test data for KT-59798 --- .../box/builderInference/issues/kt59798.kt | 28 +++++++++++++++++++ .../builderInference/issues/kt59798.fir.kt | 27 ++++++++++++++++++ .../tests/builderInference/issues/kt59798.kt | 27 ++++++++++++++++++ 3 files changed, 82 insertions(+) create mode 100644 compiler/testData/codegen/box/builderInference/issues/kt59798.kt create mode 100644 compiler/testData/diagnostics/tests/builderInference/issues/kt59798.fir.kt create mode 100644 compiler/testData/diagnostics/tests/builderInference/issues/kt59798.kt diff --git a/compiler/testData/codegen/box/builderInference/issues/kt59798.kt b/compiler/testData/codegen/box/builderInference/issues/kt59798.kt new file mode 100644 index 00000000000..515afde2e07 --- /dev/null +++ b/compiler/testData/codegen/box/builderInference/issues/kt59798.kt @@ -0,0 +1,28 @@ +// ISSUE: KT-59798 + +// IGNORE_LIGHT_ANALYSIS +// IGNORE_BACKEND_K1: ANY +// REASON: red code (see corresponding diagnostic test) + +fun box(): String { + build { + setTypeVariable(TargetType()) + getTypeVariable().let {} + } + return "OK" +} + + + + +class TargetType + +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/kt59798.fir.kt b/compiler/testData/diagnostics/tests/builderInference/issues/kt59798.fir.kt new file mode 100644 index 00000000000..60f4254e103 --- /dev/null +++ b/compiler/testData/diagnostics/tests/builderInference/issues/kt59798.fir.kt @@ -0,0 +1,27 @@ +// ISSUE: KT-59798 +// CHECK_TYPE_WITH_EXACT + +fun test() { + val buildee = build { + setTypeVariable(TargetType()) + getTypeVariable().let {} + } + // 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 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) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/builderInference/issues/kt59798.kt b/compiler/testData/diagnostics/tests/builderInference/issues/kt59798.kt new file mode 100644 index 00000000000..9ae052bb96e --- /dev/null +++ b/compiler/testData/diagnostics/tests/builderInference/issues/kt59798.kt @@ -0,0 +1,27 @@ +// ISSUE: KT-59798 +// CHECK_TYPE_WITH_EXACT + +fun test() { + val buildee = build { + setTypeVariable(TargetType()) + getTypeVariable().let {} + } + // 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 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) +}