diff --git a/compiler/testData/codegen/box/builderInference/issues/kt57834.kt b/compiler/testData/codegen/box/builderInference/issues/kt57834.kt new file mode 100644 index 00000000000..12a0563d0d5 --- /dev/null +++ b/compiler/testData/codegen/box/builderInference/issues/kt57834.kt @@ -0,0 +1,32 @@ +// ISSUE: KT-57834 + +// IGNORE_LIGHT_ANALYSIS +// IGNORE_BACKEND: ANY +// REASON: red code (see corresponding diagnostic test) + +fun box(): String { + build { + setTypeVariable(TargetType()) + consume(getTypeVariable()) + } + return "OK" +} + + + + +class TargetType +class DifferentType + +fun consume(value: TargetType) {} +fun consume(value: DifferentType) {} + +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/kt57834.fir.kt b/compiler/testData/diagnostics/tests/builderInference/issues/kt57834.fir.kt new file mode 100644 index 00000000000..95ecbdf20bf --- /dev/null +++ b/compiler/testData/diagnostics/tests/builderInference/issues/kt57834.fir.kt @@ -0,0 +1,31 @@ +// ISSUE: KT-57834 +// CHECK_TYPE_WITH_EXACT + +fun test() { + val buildee = build { + setTypeVariable(TargetType()) + consume(getTypeVariable()) + } + // 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 consume(value: TargetType) {} +fun consume(value: DifferentType) {} + +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) +} diff --git a/compiler/testData/diagnostics/tests/builderInference/issues/kt57834.kt b/compiler/testData/diagnostics/tests/builderInference/issues/kt57834.kt new file mode 100644 index 00000000000..dde309d4411 --- /dev/null +++ b/compiler/testData/diagnostics/tests/builderInference/issues/kt57834.kt @@ -0,0 +1,31 @@ +// ISSUE: KT-57834 +// CHECK_TYPE_WITH_EXACT + +fun test() { + val buildee = build { + setTypeVariable(TargetType()) + consume(getTypeVariable()) + } + // 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 consume(value: TargetType) {} +fun consume(value: DifferentType) {} + +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) +}