diff --git a/compiler/testData/codegen/box/builderInference/issues/kt63648.kt b/compiler/testData/codegen/box/builderInference/issues/kt63648.kt new file mode 100644 index 00000000000..f55e7fcc062 --- /dev/null +++ b/compiler/testData/codegen/box/builderInference/issues/kt63648.kt @@ -0,0 +1,34 @@ +// ISSUE: KT-63648 + +// 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 @ Kt63648Kt$box$1.invoke) + +fun box(): String { + build { + setTypeVariable(TargetType()) + getTypeVariable().consumeDifferentTypeReceiver() + } + return "OK" +} + + + + +class TargetType +class DifferentType + +fun DifferentType.consumeDifferentTypeReceiver() {} + +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/kt63648.fir.kt b/compiler/testData/diagnostics/tests/builderInference/issues/kt63648.fir.kt new file mode 100644 index 00000000000..b2c2b7880e3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/builderInference/issues/kt63648.fir.kt @@ -0,0 +1,30 @@ +// ISSUE: KT-63648 +// CHECK_TYPE_WITH_EXACT + +fun test() { + val buildee = build { + setTypeVariable(TargetType()) + getTypeVariable().consumeDifferentTypeReceiver() + } + // 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 DifferentType.consumeDifferentTypeReceiver() {} + +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/kt63648.kt b/compiler/testData/diagnostics/tests/builderInference/issues/kt63648.kt new file mode 100644 index 00000000000..19b6b0c7847 --- /dev/null +++ b/compiler/testData/diagnostics/tests/builderInference/issues/kt63648.kt @@ -0,0 +1,30 @@ +// ISSUE: KT-63648 +// CHECK_TYPE_WITH_EXACT + +fun test() { + val buildee = build { + setTypeVariable(TargetType()) + getTypeVariable().consumeDifferentTypeReceiver() + } + // 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 DifferentType.consumeDifferentTypeReceiver() {} + +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) +}