diff --git a/compiler/testData/codegen/box/builderInference/issues/kt55056.kt b/compiler/testData/codegen/box/builderInference/issues/kt55056.kt new file mode 100644 index 00000000000..5c305986b4c --- /dev/null +++ b/compiler/testData/codegen/box/builderInference/issues/kt55056.kt @@ -0,0 +1,41 @@ +// ISSUE: KT-55056 + +// 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 @ Kt55056Kt$box$1.invoke) + +fun box(): String { + build { + setTypeVariable(TargetType()) + consumeDifferentType(extensionReplaceOutProjectedTypeVariable(DifferentType())) + } + return "OK" +} + + + + +class TargetType +class DifferentType + +fun consumeDifferentType(value: DifferentType) {} + +class Buildee { + fun setTypeVariable(value: TV) { storage = value } + fun getTypeVariable(): TV = storage + private var storage: TV = TargetType() as TV +} + +fun Buildee.extensionReplaceOutProjectedTypeVariable(value: ETV): ETV { + this as Buildee + val temp = getTypeVariable() + setTypeVariable(value) + return temp +} + +fun build(instructions: Buildee.() -> Unit): Buildee { + return Buildee().apply(instructions) +} diff --git a/compiler/testData/diagnostics/tests/builderInference/issues/kt55056.fir.kt b/compiler/testData/diagnostics/tests/builderInference/issues/kt55056.fir.kt new file mode 100644 index 00000000000..3fb787e9a06 --- /dev/null +++ b/compiler/testData/diagnostics/tests/builderInference/issues/kt55056.fir.kt @@ -0,0 +1,34 @@ +// ISSUE: KT-55056 +// CHECK_TYPE_WITH_EXACT + +fun test() { + val buildee = build { + setTypeVariable(TargetType()) + consumeDifferentType(extensionReplaceOutProjectedTypeVariable(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 + +fun consumeDifferentType(value: DifferentType) {} + +class Buildee { + fun setTypeVariable(value: TV) { storage = value } + fun getTypeVariable(): TV = storage + private var storage: TV = null!! +} + +fun Buildee.extensionReplaceOutProjectedTypeVariable(value: ETV): ETV { + return null!! +} + +fun build(instructions: Buildee.() -> Unit): Buildee { + return Buildee().apply(instructions) +} diff --git a/compiler/testData/diagnostics/tests/builderInference/issues/kt55056.kt b/compiler/testData/diagnostics/tests/builderInference/issues/kt55056.kt new file mode 100644 index 00000000000..36d4d6a402b --- /dev/null +++ b/compiler/testData/diagnostics/tests/builderInference/issues/kt55056.kt @@ -0,0 +1,34 @@ +// ISSUE: KT-55056 +// CHECK_TYPE_WITH_EXACT + +fun test() { + val buildee = build { + setTypeVariable(TargetType()) + consumeDifferentType(extensionReplaceOutProjectedTypeVariable(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 + +fun consumeDifferentType(value: DifferentType) {} + +class Buildee { + fun setTypeVariable(value: TV) { storage = value } + fun getTypeVariable(): TV = storage + private var storage: TV = null!! +} + +fun Buildee.extensionReplaceOutProjectedTypeVariable(value: ETV): ETV { + return null!! +} + +fun build(instructions: Buildee.() -> Unit): Buildee { + return Buildee().apply(instructions) +}