From 55485a8fd627c33cfed212cc9b20a0586333228a Mon Sep 17 00:00:00 2001 From: Stanislav Ruban Date: Sat, 2 Dec 2023 15:27:18 +0100 Subject: [PATCH] [tests] Add test data for KT-57707 --- .../box/builderInference/issues/kt57707.kt | 33 +++++++++++++++++++ .../builderInference/issues/kt57707.fir.kt | 29 ++++++++++++++++ .../tests/builderInference/issues/kt57707.kt | 29 ++++++++++++++++ 3 files changed, 91 insertions(+) create mode 100644 compiler/testData/codegen/box/builderInference/issues/kt57707.kt create mode 100644 compiler/testData/diagnostics/tests/builderInference/issues/kt57707.fir.kt create mode 100644 compiler/testData/diagnostics/tests/builderInference/issues/kt57707.kt diff --git a/compiler/testData/codegen/box/builderInference/issues/kt57707.kt b/compiler/testData/codegen/box/builderInference/issues/kt57707.kt new file mode 100644 index 00000000000..11b64779798 --- /dev/null +++ b/compiler/testData/codegen/box/builderInference/issues/kt57707.kt @@ -0,0 +1,33 @@ +// ISSUE: KT-57707 + +// IGNORE_LIGHT_ANALYSIS +// IGNORE_BACKEND_K1: ANY +// REASON: red code (see corresponding diagnostic test) + +fun box(): String { + build { + setTypeVariable(TargetType()) + extensionSetOutProjectedTypeVariable(DifferentType()) + } + return "OK" +} + + + + +class TargetType +class DifferentType + +class Buildee { + fun setTypeVariable(value: TV) { storage = value } + private var storage: TV = TargetType() as TV +} + +fun Buildee.extensionSetOutProjectedTypeVariable(value: ETV) { + this as Buildee + setTypeVariable(value) +} + +fun build(instructions: Buildee.() -> Unit): Buildee { + return Buildee().apply(instructions) +} diff --git a/compiler/testData/diagnostics/tests/builderInference/issues/kt57707.fir.kt b/compiler/testData/diagnostics/tests/builderInference/issues/kt57707.fir.kt new file mode 100644 index 00000000000..efd668d09ff --- /dev/null +++ b/compiler/testData/diagnostics/tests/builderInference/issues/kt57707.fir.kt @@ -0,0 +1,29 @@ +// ISSUE: KT-57707 +// CHECK_TYPE_WITH_EXACT + +fun test() { + val buildee = build { + setTypeVariable(TargetType()) + extensionSetOutProjectedTypeVariable(DifferentType()) + } + // 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 + +class Buildee { + fun setTypeVariable(value: TV) { storage = value } + private var storage: TV = null!! +} + +fun Buildee.extensionSetOutProjectedTypeVariable(value: ETV) {} + +fun build(instructions: Buildee.() -> Unit): Buildee { + return Buildee().apply(instructions) +} diff --git a/compiler/testData/diagnostics/tests/builderInference/issues/kt57707.kt b/compiler/testData/diagnostics/tests/builderInference/issues/kt57707.kt new file mode 100644 index 00000000000..207c75ab3c7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/builderInference/issues/kt57707.kt @@ -0,0 +1,29 @@ +// ISSUE: KT-57707 +// CHECK_TYPE_WITH_EXACT + +fun test() { + val buildee = build { + setTypeVariable(TargetType()) + extensionSetOutProjectedTypeVariable(DifferentType()) + } + // 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 + +class Buildee { + fun setTypeVariable(value: TV) { storage = value } + private var storage: TV = null!! +} + +fun Buildee.extensionSetOutProjectedTypeVariable(value: ETV) {} + +fun build(instructions: Buildee.() -> Unit): Buildee { + return Buildee().apply(instructions) +}