From ce107d06d4402073ecbae3c007c91ca0751cde31 Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Thu, 17 Jun 2021 19:43:16 +0300 Subject: [PATCH] JVM_IR add test for KT-47300 --- .../FirBlackBoxCodegenTestGenerated.java | 6 ++++ .../testData/codegen/box/contracts/kt47300.kt | 36 +++++++++++++++++++ .../codegen/BlackBoxCodegenTestGenerated.java | 6 ++++ .../IrBlackBoxCodegenTestGenerated.java | 6 ++++ .../LightAnalysisModeTestGenerated.java | 5 +++ .../IrJsCodegenBoxES6TestGenerated.java | 5 +++ .../IrJsCodegenBoxTestGenerated.java | 5 +++ .../semantics/JsCodegenBoxTestGenerated.java | 5 +++ 8 files changed, 74 insertions(+) create mode 100644 compiler/testData/codegen/box/contracts/kt47300.kt diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java index cc49feaecd5..aadb64b89e4 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java @@ -7550,6 +7550,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/contracts/kt47168.kt"); } + @Test + @TestMetadata("kt47300.kt") + public void testKt47300() throws Exception { + runTest("compiler/testData/codegen/box/contracts/kt47300.kt"); + } + @Test @TestMetadata("lambdaParameter.kt") public void testLambdaParameter() throws Exception { diff --git a/compiler/testData/codegen/box/contracts/kt47300.kt b/compiler/testData/codegen/box/contracts/kt47300.kt new file mode 100644 index 00000000000..683d7d05e67 --- /dev/null +++ b/compiler/testData/codegen/box/contracts/kt47300.kt @@ -0,0 +1,36 @@ +// WITH_RUNTIME + +import kotlin.contracts.ExperimentalContracts +import kotlin.contracts.InvocationKind +import kotlin.contracts.contract + + +data class Content(val value: T) + +fun content(value: T) = Content(value) + +@ExperimentalContracts +inline fun Content.getOrElse( + onException: (exception: Exception) -> R, +): R = fold({ it }, onException) + +@ExperimentalContracts +inline fun Content.fold( + onContent: (value: T) -> R, + onException: (exception: Exception) -> R, +): R { + contract { + callsInPlace(onContent, InvocationKind.AT_MOST_ONCE) + callsInPlace(onException, InvocationKind.AT_MOST_ONCE) + } + return onContent(value) +} + + +@ExperimentalContracts +fun box(): String { + val t = content(1).getOrElse { 2 } + if (t != 1) return "Failed: $t" + + return "OK" +} diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java index 59221ee9377..a751d645f12 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java @@ -7550,6 +7550,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/contracts/kt47168.kt"); } + @Test + @TestMetadata("kt47300.kt") + public void testKt47300() throws Exception { + runTest("compiler/testData/codegen/box/contracts/kt47300.kt"); + } + @Test @TestMetadata("lambdaParameter.kt") public void testLambdaParameter() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java index 1b6b6090987..8aa2e5220f1 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java @@ -7550,6 +7550,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/contracts/kt47168.kt"); } + @Test + @TestMetadata("kt47300.kt") + public void testKt47300() throws Exception { + runTest("compiler/testData/codegen/box/contracts/kt47300.kt"); + } + @Test @TestMetadata("lambdaParameter.kt") public void testLambdaParameter() throws Exception { diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 8846a8f3237..0c0a9891b93 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -5749,6 +5749,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/contracts/kt47168.kt"); } + @TestMetadata("kt47300.kt") + public void testKt47300() throws Exception { + runTest("compiler/testData/codegen/box/contracts/kt47300.kt"); + } + @TestMetadata("lambdaParameter.kt") public void testLambdaParameter() throws Exception { runTest("compiler/testData/codegen/box/contracts/lambdaParameter.kt"); diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java index eb26572c7f6..a708841a4e5 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java @@ -5023,6 +5023,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes runTest("compiler/testData/codegen/box/contracts/kt47168.kt"); } + @TestMetadata("kt47300.kt") + public void testKt47300() throws Exception { + runTest("compiler/testData/codegen/box/contracts/kt47300.kt"); + } + @TestMetadata("lambdaParameter.kt") public void testLambdaParameter() throws Exception { runTest("compiler/testData/codegen/box/contracts/lambdaParameter.kt"); diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java index d2a0ab20687..38d89fd8b8a 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java @@ -4429,6 +4429,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { runTest("compiler/testData/codegen/box/contracts/kt47168.kt"); } + @TestMetadata("kt47300.kt") + public void testKt47300() throws Exception { + runTest("compiler/testData/codegen/box/contracts/kt47300.kt"); + } + @TestMetadata("lambdaParameter.kt") public void testLambdaParameter() throws Exception { runTest("compiler/testData/codegen/box/contracts/lambdaParameter.kt"); diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java index a5ae9443a52..4fb00b1eb71 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java @@ -4429,6 +4429,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { runTest("compiler/testData/codegen/box/contracts/kt47168.kt"); } + @TestMetadata("kt47300.kt") + public void testKt47300() throws Exception { + runTest("compiler/testData/codegen/box/contracts/kt47300.kt"); + } + @TestMetadata("lambdaParameter.kt") public void testLambdaParameter() throws Exception { runTest("compiler/testData/codegen/box/contracts/lambdaParameter.kt");