From 2bcaa3eb8f88a1cb66d02a35c91f6ba6de747b8a Mon Sep 17 00:00:00 2001 From: Stanislav Ruban Date: Sat, 2 Dec 2023 15:29:18 +0100 Subject: [PATCH] [tests] Add test data for KT-63733 --- .../box/builderInference/issues/kt63733.kt | 35 +++++++++++++++++++ .../builderInference/issues/kt63733.fir.kt | 34 ++++++++++++++++++ .../tests/builderInference/issues/kt63733.kt | 34 ++++++++++++++++++ 3 files changed, 103 insertions(+) create mode 100644 compiler/testData/codegen/box/builderInference/issues/kt63733.kt create mode 100644 compiler/testData/diagnostics/tests/builderInference/issues/kt63733.fir.kt create mode 100644 compiler/testData/diagnostics/tests/builderInference/issues/kt63733.kt diff --git a/compiler/testData/codegen/box/builderInference/issues/kt63733.kt b/compiler/testData/codegen/box/builderInference/issues/kt63733.kt new file mode 100644 index 00000000000..b917c1744fc --- /dev/null +++ b/compiler/testData/codegen/box/builderInference/issues/kt63733.kt @@ -0,0 +1,35 @@ +// ISSUE: KT-63733 + +// IGNORE_LIGHT_ANALYSIS +// IGNORE_BACKEND: ANY +// REASON: red code (see corresponding diagnostic test) + +fun BoundedBuildee.setBoundedTypeVariable(arg: DifferentType) {} + +fun box(): String { + boundedBuild { + setBoundedTypeVariable(TargetType()) + setBoundedTypeVariable(DifferentType()) + } + boundedBuild { + setBoundedTypeVariable(TargetType()) + setBoundedTypeVariable(DifferentType()) + } + return "OK" +} + + + + +open class TargetTypeBase +class TargetType: TargetTypeBase() +class DifferentType + +class BoundedBuildee { + fun setBoundedTypeVariable(value: BTV) { storage = value } + private var storage: BTV = TargetType() as BTV +} + +fun boundedBuild(instructions: BoundedBuildee.() -> Unit): BoundedBuildee { + return BoundedBuildee().apply(instructions) +} diff --git a/compiler/testData/diagnostics/tests/builderInference/issues/kt63733.fir.kt b/compiler/testData/diagnostics/tests/builderInference/issues/kt63733.fir.kt new file mode 100644 index 00000000000..7617d95762c --- /dev/null +++ b/compiler/testData/diagnostics/tests/builderInference/issues/kt63733.fir.kt @@ -0,0 +1,34 @@ +// ISSUE: KT-63733 +// CHECK_TYPE_WITH_EXACT + +fun BoundedBuildee.setBoundedTypeVariable(arg: DifferentType) {} + +fun test() { + boundedBuild { + setBoundedTypeVariable(TargetType()) + setBoundedTypeVariable(DifferentType()) + } + val buildee = boundedBuild { + setBoundedTypeVariable(TargetType()) + setBoundedTypeVariable(DifferentType()) + } + // 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>(; BoundedBuildee")!>buildee) +} + + + + +open class TargetTypeBase +class TargetType: TargetTypeBase() +class DifferentType + +class BoundedBuildee { + fun setBoundedTypeVariable(value: BTV) { storage = value } + private var storage: BTV = null!! +} + +fun boundedBuild(instructions: BoundedBuildee.() -> Unit): BoundedBuildee { + return BoundedBuildee().apply(instructions) +} diff --git a/compiler/testData/diagnostics/tests/builderInference/issues/kt63733.kt b/compiler/testData/diagnostics/tests/builderInference/issues/kt63733.kt new file mode 100644 index 00000000000..e490c2b2dfe --- /dev/null +++ b/compiler/testData/diagnostics/tests/builderInference/issues/kt63733.kt @@ -0,0 +1,34 @@ +// ISSUE: KT-63733 +// CHECK_TYPE_WITH_EXACT + +fun BoundedBuildee.setBoundedTypeVariable(arg: DifferentType) {} + +fun test() { + boundedBuild { + setBoundedTypeVariable(TargetType()) + setBoundedTypeVariable(DifferentType()) + } + val buildee = boundedBuild { + setBoundedTypeVariable(TargetType()) + setBoundedTypeVariable(DifferentType()) + } + // 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>(; BoundedBuildee"), TYPE_MISMATCH("BoundedBuildee; BoundedBuildee")!>buildee) +} + + + + +open class TargetTypeBase +class TargetType: TargetTypeBase() +class DifferentType + +class BoundedBuildee { + fun setBoundedTypeVariable(value: BTV) { storage = value } + private var storage: BTV = null!! +} + +fun boundedBuild(instructions: BoundedBuildee.() -> Unit): BoundedBuildee { + return BoundedBuildee().apply(instructions) +}