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) +}