diff --git a/compiler/testData/codegen/box/builderInference/issues/kt53639.kt b/compiler/testData/codegen/box/builderInference/issues/kt53639.kt new file mode 100644 index 00000000000..9236053eb09 --- /dev/null +++ b/compiler/testData/codegen/box/builderInference/issues/kt53639.kt @@ -0,0 +1,41 @@ +// ISSUE: KT-53639 + +// IGNORE_LIGHT_ANALYSIS +// IGNORE_BACKEND: ANY +// REASON: red code in K1 (see corresponding diagnostic test) +// REASON: compile-time failure in K2/JVM (java.lang.IllegalStateException: Cannot serialize error type: ERROR CLASS: Cannot infer argument for type parameter PTV) +// REASON: compile-time failure in K2/Native, K2/WASM, K2/JS (org.jetbrains.kotlin.backend.common.linkage.issues.IrDisallowedErrorNode: Class found but error nodes are not allowed) + +fun box(): String { + val buildee = initializeAndBuild( + { build { setTypeVariable(TargetType()) } }, + { placeholderExtensionInvokeOnBuildee() }, + ) + consumeTargetTypeBuildee(buildee) + return "OK" +} + + + + +class TargetType + +fun consumeTargetTypeBuildee(value: Buildee) {} + +class Buildee { + fun setTypeVariable(value: TV) { storage = value } + private var storage: TV = TargetType() as TV +} + +fun Buildee.placeholderExtensionInvokeOnBuildee() {} + +fun build(instructions: Buildee.() -> Unit): Buildee { + return Buildee().apply(instructions) +} + +fun initializeAndBuild( + initializer: () -> Buildee, + instructions: Buildee.() -> Unit +): Buildee { + return initializer().apply(instructions) +} diff --git a/compiler/testData/diagnostics/tests/builderInference/issues/kt53639.fir.kt b/compiler/testData/diagnostics/tests/builderInference/issues/kt53639.fir.kt new file mode 100644 index 00000000000..d79f49cd6e3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/builderInference/issues/kt53639.fir.kt @@ -0,0 +1,35 @@ +// ISSUE: KT-53639 +// CHECK_TYPE_WITH_EXACT + +fun test() { + val buildee = initializeAndBuild( + { build { setTypeVariable(TargetType()) } }, + { placeholderExtensionInvokeOnBuildee() }, + ) + // 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 Buildee { + fun setTypeVariable(value: TV) { storage = value } + private var storage: TV = null!! +} + +fun Buildee.placeholderExtensionInvokeOnBuildee() {} + +fun build(instructions: Buildee.() -> Unit): Buildee { + return Buildee().apply(instructions) +} + +fun initializeAndBuild( + initializer: () -> Buildee, + instructions: Buildee.() -> Unit +): Buildee { + return initializer().apply(instructions) +} diff --git a/compiler/testData/diagnostics/tests/builderInference/issues/kt53639.kt b/compiler/testData/diagnostics/tests/builderInference/issues/kt53639.kt new file mode 100644 index 00000000000..dc141e7c9f3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/builderInference/issues/kt53639.kt @@ -0,0 +1,35 @@ +// ISSUE: KT-53639 +// CHECK_TYPE_WITH_EXACT + +fun test() { + val buildee = initializeAndBuild( + { build { setTypeVariable(TargetType()) } }, + { placeholderExtensionInvokeOnBuildee() }, + ) + // 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"), TYPE_MISMATCH("Buildee; Buildee")!>buildee) +} + + + + +class TargetType + +class Buildee { + fun setTypeVariable(value: TV) { storage = value } + private var storage: TV = null!! +} + +fun Buildee.placeholderExtensionInvokeOnBuildee() {} + +fun build(instructions: Buildee.() -> Unit): Buildee { + return Buildee().apply(instructions) +} + +fun initializeAndBuild( + initializer: () -> Buildee, + instructions: Buildee.() -> Unit +): Buildee { + return initializer().apply(instructions) +}