From cef44cfa7d803e7ced815187c93f7841595eb5f4 Mon Sep 17 00:00:00 2001 From: Stanislav Ruban Date: Thu, 30 Nov 2023 22:02:41 +0100 Subject: [PATCH] [tests] Add test data for KT-47989 --- .../box/builderInference/issues/kt47989a.kt | 32 +++++++++++++++++++ .../box/builderInference/issues/kt47989b.kt | 29 +++++++++++++++++ .../builderInference/issues/kt47989a.fir.kt | 31 ++++++++++++++++++ .../tests/builderInference/issues/kt47989a.kt | 31 ++++++++++++++++++ .../builderInference/issues/kt47989b.fir.kt | 28 ++++++++++++++++ .../tests/builderInference/issues/kt47989b.kt | 28 ++++++++++++++++ 6 files changed, 179 insertions(+) create mode 100644 compiler/testData/codegen/box/builderInference/issues/kt47989a.kt create mode 100644 compiler/testData/codegen/box/builderInference/issues/kt47989b.kt create mode 100644 compiler/testData/diagnostics/tests/builderInference/issues/kt47989a.fir.kt create mode 100644 compiler/testData/diagnostics/tests/builderInference/issues/kt47989a.kt create mode 100644 compiler/testData/diagnostics/tests/builderInference/issues/kt47989b.fir.kt create mode 100644 compiler/testData/diagnostics/tests/builderInference/issues/kt47989b.kt diff --git a/compiler/testData/codegen/box/builderInference/issues/kt47989a.kt b/compiler/testData/codegen/box/builderInference/issues/kt47989a.kt new file mode 100644 index 00000000000..c4650b3fb71 --- /dev/null +++ b/compiler/testData/codegen/box/builderInference/issues/kt47989a.kt @@ -0,0 +1,32 @@ +// ISSUE: KT-47989 + +// IGNORE_LIGHT_ANALYSIS +// IGNORE_BACKEND: ANY +// REASON: red code (see corresponding diagnostic test) + +fun box(): String { + build { + object: TypeSourceInterface { + override fun produceTargetType() = getTypeVariable() + } + } + return "OK" +} + + + + +class TargetType + +interface TypeSourceInterface { + fun produceTargetType(): TargetType +} + +class Buildee { + 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/codegen/box/builderInference/issues/kt47989b.kt b/compiler/testData/codegen/box/builderInference/issues/kt47989b.kt new file mode 100644 index 00000000000..1378ff24463 --- /dev/null +++ b/compiler/testData/codegen/box/builderInference/issues/kt47989b.kt @@ -0,0 +1,29 @@ +// ISSUE: KT-47989 + +// IGNORE_LIGHT_ANALYSIS +// IGNORE_BACKEND: ANY +// REASON: red code (see corresponding diagnostic test) + +fun box(): String { + build { + object: TypeSourceInterface { + override fun produceTargetTypeBuildee() = this@build + } + } + return "OK" +} + + + + +class TargetType + +interface TypeSourceInterface { + fun produceTargetTypeBuildee(): Buildee +} + +class Buildee + +fun build(instructions: Buildee.() -> Unit): Buildee { + return Buildee().apply(instructions) +} diff --git a/compiler/testData/diagnostics/tests/builderInference/issues/kt47989a.fir.kt b/compiler/testData/diagnostics/tests/builderInference/issues/kt47989a.fir.kt new file mode 100644 index 00000000000..1a8490741a7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/builderInference/issues/kt47989a.fir.kt @@ -0,0 +1,31 @@ +// ISSUE: KT-47989 +// CHECK_TYPE_WITH_EXACT + +fun test() { + val buildee = build { + object: TypeSourceInterface { + override fun produceTargetType() = 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) +} + + + + +class TargetType + +interface TypeSourceInterface { + fun produceTargetType(): TargetType +} + +class Buildee { + 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/kt47989a.kt b/compiler/testData/diagnostics/tests/builderInference/issues/kt47989a.kt new file mode 100644 index 00000000000..b143b6f562c --- /dev/null +++ b/compiler/testData/diagnostics/tests/builderInference/issues/kt47989a.kt @@ -0,0 +1,31 @@ +// ISSUE: KT-47989 +// CHECK_TYPE_WITH_EXACT + +fun test() { + val buildee = build { + object: TypeSourceInterface { + override fun produceTargetType() = 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 + +interface TypeSourceInterface { + fun produceTargetType(): TargetType +} + +class Buildee { + 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/kt47989b.fir.kt b/compiler/testData/diagnostics/tests/builderInference/issues/kt47989b.fir.kt new file mode 100644 index 00000000000..d295ffdee9b --- /dev/null +++ b/compiler/testData/diagnostics/tests/builderInference/issues/kt47989b.fir.kt @@ -0,0 +1,28 @@ +// ISSUE: KT-47989 +// CHECK_TYPE_WITH_EXACT + +fun test() { + val buildee = build { + object: TypeSourceInterface { + override fun produceTargetTypeBuildee() = this@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>(buildee) +} + + + + +class TargetType + +interface TypeSourceInterface { + fun produceTargetTypeBuildee(): Buildee +} + +class Buildee + +fun build(instructions: Buildee.() -> Unit): Buildee { + return Buildee().apply(instructions) +} diff --git a/compiler/testData/diagnostics/tests/builderInference/issues/kt47989b.kt b/compiler/testData/diagnostics/tests/builderInference/issues/kt47989b.kt new file mode 100644 index 00000000000..907c9a3795d --- /dev/null +++ b/compiler/testData/diagnostics/tests/builderInference/issues/kt47989b.kt @@ -0,0 +1,28 @@ +// ISSUE: KT-47989 +// CHECK_TYPE_WITH_EXACT + +fun test() { + val buildee = build { + object: TypeSourceInterface { + override fun produceTargetTypeBuildee() = this@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 + +interface TypeSourceInterface { + fun produceTargetTypeBuildee(): Buildee +} + +class Buildee + +fun build(instructions: Buildee.() -> Unit): Buildee { + return Buildee().apply(instructions) +}