diff --git a/compiler/testData/codegen/box/builderInference/issues/kt52838a.kt b/compiler/testData/codegen/box/builderInference/issues/kt52838a.kt new file mode 100644 index 00000000000..1d2c6ae116a --- /dev/null +++ b/compiler/testData/codegen/box/builderInference/issues/kt52838a.kt @@ -0,0 +1,30 @@ +// ISSUE: KT-52838 + +// IGNORE_LIGHT_ANALYSIS +// IGNORE_BACKEND: ANY +// REASON: red code (see corresponding diagnostic test) + +fun box(): String { + build { + this as DerivedBuildee<*, *> + getTypeVariableA() + getTypeVariableB() + } + return "OK" +} + + + + +open class Buildee { + fun getTypeVariableA(): TVA = storageA + fun getTypeVariableB(): TVB = storageB + private var storageA: TVA = Any() as TVA + private var storageB: TVB = Any() as TVB +} + +class DerivedBuildee: Buildee() + +fun build(instructions: Buildee.() -> Unit): Buildee { + return DerivedBuildee().apply(instructions) +} diff --git a/compiler/testData/codegen/box/builderInference/issues/kt52838b.kt b/compiler/testData/codegen/box/builderInference/issues/kt52838b.kt new file mode 100644 index 00000000000..75f793a5945 --- /dev/null +++ b/compiler/testData/codegen/box/builderInference/issues/kt52838b.kt @@ -0,0 +1,28 @@ +// ISSUE: KT-52838 + +// IGNORE_LIGHT_ANALYSIS +// IGNORE_BACKEND: ANY +// REASON: red code (see corresponding diagnostic test) + +fun box(): String { + build { + this as DerivedBuildee<*> + getTypeVariable() + getTypeVariable() + } + return "OK" +} + + + + +open class Buildee { + fun getTypeVariable(): TV = storage + private var storage: TV = Any() as TV +} + +class DerivedBuildee: Buildee() + +fun build(instructions: Buildee.() -> Unit): Buildee { + return DerivedBuildee().apply(instructions) +} diff --git a/compiler/testData/codegen/box/builderInference/issues/kt52838c.kt b/compiler/testData/codegen/box/builderInference/issues/kt52838c.kt new file mode 100644 index 00000000000..234db24b4f3 --- /dev/null +++ b/compiler/testData/codegen/box/builderInference/issues/kt52838c.kt @@ -0,0 +1,26 @@ +// ISSUE: KT-52838 + +// IGNORE_BACKEND_K2: ANY +// REASON: red code (see corresponding diagnostic test) + +fun box(): String { + build { + this as DerivedBuildee<*> + getTypeVariable() + } + return "OK" +} + + + + +open class Buildee { + fun getTypeVariable(): TV = storage + private var storage: TV = Any() as TV +} + +class DerivedBuildee: Buildee() + +fun build(instructions: Buildee.() -> Unit): Buildee { + return DerivedBuildee().apply(instructions) +} diff --git a/compiler/testData/diagnostics/tests/builderInference/issues/kt52838a.fir.kt b/compiler/testData/diagnostics/tests/builderInference/issues/kt52838a.fir.kt new file mode 100644 index 00000000000..aab51a0fc70 --- /dev/null +++ b/compiler/testData/diagnostics/tests/builderInference/issues/kt52838a.fir.kt @@ -0,0 +1,29 @@ +// ISSUE: KT-52838 +// CHECK_TYPE_WITH_EXACT + +fun test() { + val buildee = build { + this as DerivedBuildee<*, *> + getTypeVariableA() + getTypeVariableB() + } + // 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<*, *>>(buildee) +} + + + + +open class Buildee { + fun getTypeVariableA(): TVA = storageA + fun getTypeVariableB(): TVB = storageB + private var storageA: TVA = null!! + private var storageB: TVB = null!! +} + +class DerivedBuildee: Buildee() + +fun build(instructions: Buildee.() -> Unit): Buildee { + return DerivedBuildee().apply(instructions) +} diff --git a/compiler/testData/diagnostics/tests/builderInference/issues/kt52838a.kt b/compiler/testData/diagnostics/tests/builderInference/issues/kt52838a.kt new file mode 100644 index 00000000000..6f48245ed3e --- /dev/null +++ b/compiler/testData/diagnostics/tests/builderInference/issues/kt52838a.kt @@ -0,0 +1,29 @@ +// ISSUE: KT-52838 +// CHECK_TYPE_WITH_EXACT + +fun test() { + val buildee = build { + this as DerivedBuildee<*, *> + getTypeVariableA() + getTypeVariableB() + } + // 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<*, *>")!>buildee) +} + + + + +open class Buildee { + fun getTypeVariableA(): TVA = storageA + fun getTypeVariableB(): TVB = storageB + private var storageA: TVA = null!! + private var storageB: TVB = null!! +} + +class DerivedBuildee: Buildee() + +fun build(instructions: Buildee.() -> Unit): Buildee { + return DerivedBuildee().apply(instructions) +} diff --git a/compiler/testData/diagnostics/tests/builderInference/issues/kt52838b.fir.kt b/compiler/testData/diagnostics/tests/builderInference/issues/kt52838b.fir.kt new file mode 100644 index 00000000000..3be9a0a7e98 --- /dev/null +++ b/compiler/testData/diagnostics/tests/builderInference/issues/kt52838b.fir.kt @@ -0,0 +1,27 @@ +// ISSUE: KT-52838 +// CHECK_TYPE_WITH_EXACT + +fun test() { + val buildee = build { + this as DerivedBuildee<*> + getTypeVariable() + 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<*>>(buildee) +} + + + + +open class Buildee { + fun getTypeVariable(): TV = storage + private var storage: TV = null!! +} + +class DerivedBuildee: Buildee() + +fun build(instructions: Buildee.() -> Unit): Buildee { + return DerivedBuildee().apply(instructions) +} diff --git a/compiler/testData/diagnostics/tests/builderInference/issues/kt52838b.kt b/compiler/testData/diagnostics/tests/builderInference/issues/kt52838b.kt new file mode 100644 index 00000000000..3a4e75dc8f5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/builderInference/issues/kt52838b.kt @@ -0,0 +1,27 @@ +// ISSUE: KT-52838 +// CHECK_TYPE_WITH_EXACT + +fun test() { + val buildee = build { + this as DerivedBuildee<*> + getTypeVariable() + 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<*>")!>buildee) +} + + + + +open class Buildee { + fun getTypeVariable(): TV = storage + private var storage: TV = null!! +} + +class DerivedBuildee: Buildee() + +fun build(instructions: Buildee.() -> Unit): Buildee { + return DerivedBuildee().apply(instructions) +} diff --git a/compiler/testData/diagnostics/tests/builderInference/issues/kt52838c.fir.kt b/compiler/testData/diagnostics/tests/builderInference/issues/kt52838c.fir.kt new file mode 100644 index 00000000000..ce356f538f1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/builderInference/issues/kt52838c.fir.kt @@ -0,0 +1,26 @@ +// ISSUE: KT-52838 +// CHECK_TYPE_WITH_EXACT + +fun test() { + val buildee = build { + this as DerivedBuildee<*> + 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<*>>(buildee) +} + + + + +open class Buildee { + fun getTypeVariable(): TV = storage + private var storage: TV = null!! +} + +class DerivedBuildee: Buildee() + +fun build(instructions: Buildee.() -> Unit): Buildee { + return DerivedBuildee().apply(instructions) +} diff --git a/compiler/testData/diagnostics/tests/builderInference/issues/kt52838c.kt b/compiler/testData/diagnostics/tests/builderInference/issues/kt52838c.kt new file mode 100644 index 00000000000..b2078ca3aaa --- /dev/null +++ b/compiler/testData/diagnostics/tests/builderInference/issues/kt52838c.kt @@ -0,0 +1,26 @@ +// ISSUE: KT-52838 +// CHECK_TYPE_WITH_EXACT + +fun test() { + val buildee = build { + this as DerivedBuildee<*> + 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<*>")!>buildee) +} + + + + +open class Buildee { + fun getTypeVariable(): TV = storage + private var storage: TV = null!! +} + +class DerivedBuildee: Buildee() + +fun build(instructions: Buildee.() -> Unit): Buildee { + return DerivedBuildee().apply(instructions) +}