diff --git a/compiler/testData/codegen/box/builderInference/issues/kt52757.kt b/compiler/testData/codegen/box/builderInference/issues/kt52757.kt new file mode 100644 index 00000000000..74683111e57 --- /dev/null +++ b/compiler/testData/codegen/box/builderInference/issues/kt52757.kt @@ -0,0 +1,30 @@ +// ISSUE: KT-52757 + +// IGNORE_LIGHT_ANALYSIS +// IGNORE_BACKEND_K1: ANY +// REASON: compile-time failure in K1/JVM (java.lang.AssertionError: Could not load module @ org.jetbrains.kotlin.backend.common.serialization.KotlinIrLinker.resolveModuleDeserializer) +// REASON: compile-time failure in K1/Native, K1/WASM, K1/JS (java.lang.NullPointerException @ org.jetbrains.kotlin.backend.common.serialization.mangle.descriptor.DescriptorExportCheckerVisitor.isExported) + +fun box(): String { + build { + typeVariableConsumer = ::consumeTargetType + typeVariableConsumer = {} + } + return "OK" +} + + + + +class TargetType + +fun consumeTargetType(value: TargetType) {} + +class Buildee { + var typeVariableConsumer: (TV) -> Unit = { storage = it } + 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/kt52757.kt b/compiler/testData/diagnostics/tests/builderInference/issues/kt52757.kt new file mode 100644 index 00000000000..98dae0de7e9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/builderInference/issues/kt52757.kt @@ -0,0 +1,29 @@ +// ISSUE: KT-52757 +// FIR_IDENTICAL +// CHECK_TYPE_WITH_EXACT + +fun test() { + val buildee = build { + typeVariableConsumer = ::consumeTargetType + typeVariableConsumer = {} + } + // 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 + +fun consumeTargetType(value: TargetType) {} + +class Buildee { + var typeVariableConsumer: (TV) -> Unit = { storage = it } + private var storage: TV = null!! +} + +fun build(instructions: Buildee.() -> Unit): Buildee { + return Buildee().apply(instructions) +}