diff --git a/compiler/testData/codegen/box/builderInference/issues/kt60291a.kt b/compiler/testData/codegen/box/builderInference/issues/kt60291a.kt new file mode 100644 index 00000000000..0b31efc5719 --- /dev/null +++ b/compiler/testData/codegen/box/builderInference/issues/kt60291a.kt @@ -0,0 +1,32 @@ +// ISSUE: KT-60291 +// WITH_STDLIB + +// 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 { + selectBuildee( + build { setTypeVariable(TargetType()) }, + build {} + ) + return "OK" +} + + + + +fun selectBuildee(vararg values: Buildee): Buildee = values.first() + +class TargetType + +class Buildee { + fun setTypeVariable(value: TV) { storage = value } + private var storage: TV = TargetType() as TV +} + +fun build(instructions: Buildee.() -> Unit): Buildee { + return Buildee().apply(instructions) +} diff --git a/compiler/testData/codegen/box/builderInference/issues/kt60291b.kt b/compiler/testData/codegen/box/builderInference/issues/kt60291b.kt new file mode 100644 index 00000000000..6bf3077aa1f --- /dev/null +++ b/compiler/testData/codegen/box/builderInference/issues/kt60291b.kt @@ -0,0 +1,30 @@ +// ISSUE: KT-60291 + +// IGNORE_LIGHT_ANALYSIS +// IGNORE_BACKEND_K1: ANY +// REASON: red code (see corresponding diagnostic test) + +// IGNORE_BACKEND_K2: NATIVE, WASM, JS_IR, JS_IR_ES6 +// REASON: compile-time failure (org.jetbrains.kotlin.backend.common.linkage.issues.IrDisallowedErrorNode: Class found but error nodes are not allowed) + +fun box(): String { + if (true) + build { setTypeVariable(TargetType()) } + else + build {} + return "OK" +} + + + + +class TargetType + +class Buildee { + fun setTypeVariable(value: TV) { storage = value } + private var storage: TV = TargetType() as TV +} + +fun build(instructions: Buildee.() -> Unit): Buildee { + return Buildee().apply(instructions) +} diff --git a/compiler/testData/codegen/box/builderInference/issues/kt60291c.kt b/compiler/testData/codegen/box/builderInference/issues/kt60291c.kt new file mode 100644 index 00000000000..b29a8f401c2 --- /dev/null +++ b/compiler/testData/codegen/box/builderInference/issues/kt60291c.kt @@ -0,0 +1,30 @@ +// ISSUE: KT-60291 + +// 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 { + when ("") { + "true" -> build { setTypeVariable(TargetType()) } + "false" -> build {} + else -> Buildee() + } + return "OK" +} + + + + +class TargetType + +class Buildee { + fun setTypeVariable(value: TV) { storage = value } + 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/kt60291a.fir.kt b/compiler/testData/diagnostics/tests/builderInference/issues/kt60291a.fir.kt new file mode 100644 index 00000000000..560e7995c99 --- /dev/null +++ b/compiler/testData/diagnostics/tests/builderInference/issues/kt60291a.fir.kt @@ -0,0 +1,29 @@ +// ISSUE: KT-60291 +// CHECK_TYPE_WITH_EXACT +// WITH_STDLIB + +fun test() { + val buildee = selectBuildee( + build { setTypeVariable(TargetType()) }, + build {} + ) + // 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) +} + + + + +fun selectBuildee(vararg values: Buildee): Buildee = values.first() + +class TargetType + +class Buildee { + fun setTypeVariable(value: TV) { storage = value } + private var storage: TV = null!! +} + +fun build(instructions: Buildee.() -> Unit): Buildee { + return Buildee().apply(instructions) +} diff --git a/compiler/testData/diagnostics/tests/builderInference/issues/kt60291a.kt b/compiler/testData/diagnostics/tests/builderInference/issues/kt60291a.kt new file mode 100644 index 00000000000..8477c928387 --- /dev/null +++ b/compiler/testData/diagnostics/tests/builderInference/issues/kt60291a.kt @@ -0,0 +1,29 @@ +// ISSUE: KT-60291 +// CHECK_TYPE_WITH_EXACT +// WITH_STDLIB + +fun test() { + val buildee = selectBuildee( + build { setTypeVariable(TargetType()) }, + build {} + ) + // 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) +} + + + + +fun selectBuildee(vararg values: Buildee): Buildee = values.first() + +class TargetType + +class Buildee { + fun setTypeVariable(value: TV) { storage = value } + private var storage: TV = null!! +} + +fun build(instructions: Buildee.() -> Unit): Buildee { + return Buildee().apply(instructions) +} diff --git a/compiler/testData/diagnostics/tests/builderInference/issues/kt60291b.fir.kt b/compiler/testData/diagnostics/tests/builderInference/issues/kt60291b.fir.kt new file mode 100644 index 00000000000..385a9dd2e7c --- /dev/null +++ b/compiler/testData/diagnostics/tests/builderInference/issues/kt60291b.fir.kt @@ -0,0 +1,26 @@ +// ISSUE: KT-60291 +// CHECK_TYPE_WITH_EXACT + +fun test() { + val buildee = if (true) + build { setTypeVariable(TargetType()) } + else + build {} + // 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 build(instructions: Buildee.() -> Unit): Buildee { + return Buildee().apply(instructions) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/builderInference/issues/kt60291b.kt b/compiler/testData/diagnostics/tests/builderInference/issues/kt60291b.kt new file mode 100644 index 00000000000..0179a242c2f --- /dev/null +++ b/compiler/testData/diagnostics/tests/builderInference/issues/kt60291b.kt @@ -0,0 +1,26 @@ +// ISSUE: KT-60291 +// CHECK_TYPE_WITH_EXACT + +fun test() { + val buildee = if (true) + build { setTypeVariable(TargetType()) } + else + build {} + // 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 build(instructions: Buildee.() -> Unit): Buildee { + return Buildee().apply(instructions) +} diff --git a/compiler/testData/diagnostics/tests/builderInference/issues/kt60291c.fir.kt b/compiler/testData/diagnostics/tests/builderInference/issues/kt60291c.fir.kt new file mode 100644 index 00000000000..d21082a4410 --- /dev/null +++ b/compiler/testData/diagnostics/tests/builderInference/issues/kt60291c.fir.kt @@ -0,0 +1,27 @@ +// ISSUE: KT-60291 +// CHECK_TYPE_WITH_EXACT + +fun test() { + val buildee = when ("") { + "true" -> build { setTypeVariable(TargetType()) } + "false" -> build {} + else -> Buildee() + } + // 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 build(instructions: Buildee.() -> Unit): Buildee { + return Buildee().apply(instructions) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/builderInference/issues/kt60291c.kt b/compiler/testData/diagnostics/tests/builderInference/issues/kt60291c.kt new file mode 100644 index 00000000000..3164082d6cc --- /dev/null +++ b/compiler/testData/diagnostics/tests/builderInference/issues/kt60291c.kt @@ -0,0 +1,27 @@ +// ISSUE: KT-60291 +// CHECK_TYPE_WITH_EXACT + +fun test() { + val buildee = when ("") { + "true" -> build { setTypeVariable(TargetType()) } + "false" -> build {} + else -> Buildee() + } + // 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 build(instructions: Buildee.() -> Unit): Buildee { + return Buildee().apply(instructions) +}