diff --git a/compiler/testData/codegen/box/builderInference/issues/kt55252.kt b/compiler/testData/codegen/box/builderInference/issues/kt55252.kt new file mode 100644 index 00000000000..30dabac08a0 --- /dev/null +++ b/compiler/testData/codegen/box/builderInference/issues/kt55252.kt @@ -0,0 +1,24 @@ +// ISSUE: KT-55252 + +// IGNORE_BACKEND_K1: NATIVE +// REASON: compile-time failure (java.lang.NullPointerException @ org.jetbrains.kotlin.library.metadata.KlibModuleOriginKt.getKlibModuleOrigin) + +fun box(): String { + build { + setTypeVariableProducerFunction {} + } + return "OK" +} + + + + +class Buildee { + var typeVariableProducer: () -> TV = { storage } + fun setTypeVariableProducerFunction(producer: () -> TV) { typeVariableProducer = producer } + private var storage: TV = Unit as TV +} + +fun build(instructions: Buildee.() -> Unit): Buildee { + return Buildee().apply(instructions) +} diff --git a/compiler/testData/diagnostics/tests/builderInference/issues/kt55057.fir.kt b/compiler/testData/diagnostics/tests/builderInference/issues/kt55057.fir.kt new file mode 100644 index 00000000000..6f2046fed21 --- /dev/null +++ b/compiler/testData/diagnostics/tests/builderInference/issues/kt55057.fir.kt @@ -0,0 +1,42 @@ +// ISSUE: KT-55057 +// CHECK_TYPE_WITH_EXACT +// WITH_STDLIB + +import kotlin.experimental.ExperimentalTypeInference + +fun Buildee.yieldWithoutAnnotation(value: ETV) {} + +@OptIn(ExperimentalTypeInference::class) +@BuilderInference // note: this annotation was never intended to be used on functions without lambdas +fun Buildee.yieldWithAnnotation(t: ETV) {} + +fun test() { + val buildeeA = build { + yieldWithoutAnnotation(materializeBuildee()) + yieldWithoutAnnotation(materializeBuildee()) + } + // 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>>(buildeeA) + + val buildeeB = build { + yieldWithAnnotation(materializeBuildee()) + yieldWithAnnotation(materializeBuildee()) + } + // 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>>(buildeeB) +} + + + + +fun materializeBuildee(): Buildee = Buildee() + +class TargetType + +class Buildee + +fun build(instructions: Buildee.() -> Unit): Buildee { + return Buildee().apply(instructions) +} diff --git a/compiler/testData/diagnostics/tests/builderInference/issues/kt55057.kt b/compiler/testData/diagnostics/tests/builderInference/issues/kt55057.kt new file mode 100644 index 00000000000..046ad602808 --- /dev/null +++ b/compiler/testData/diagnostics/tests/builderInference/issues/kt55057.kt @@ -0,0 +1,42 @@ +// ISSUE: KT-55057 +// CHECK_TYPE_WITH_EXACT +// WITH_STDLIB + +import kotlin.experimental.ExperimentalTypeInference + +fun Buildee.yieldWithoutAnnotation(value: ETV) {} + +@OptIn(ExperimentalTypeInference::class) +@BuilderInference // note: this annotation was never intended to be used on functions without lambdas +fun Buildee.yieldWithAnnotation(t: ETV) {} + +fun test() { + val buildeeA = build { + yieldWithoutAnnotation(materializeBuildee()) + yieldWithoutAnnotation(materializeBuildee()) + } + // 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>>(buildeeA) + + val buildeeB = build { + yieldWithAnnotation(materializeBuildee()) + yieldWithAnnotation(materializeBuildee()) + } + // 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>>(buildeeB) +} + + + + +fun materializeBuildee(): Buildee = Buildee() + +class TargetType + +class Buildee + +fun build(instructions: Buildee.() -> Unit): Buildee { + return Buildee().apply(instructions) +}