From 511c9f86b1a2b721461c773ab49c85aa141df104 Mon Sep 17 00:00:00 2001 From: Mikhael Bogdanov Date: Thu, 18 May 2017 10:36:27 +0200 Subject: [PATCH] Add new test on receiver clash during default lambda inlining --- .../lambdaInlining/receiverClash.kt | 19 +++++++++ .../lambdaInlining/receiverClash2.kt | 21 ++++++++++ .../lambdaInlining/receiverClashInClass.kt | 22 ++++++++++ .../lambdaInlining/receiverClashInClass2.kt | 24 +++++++++++ .../lambdaInlining/simpleExtension.kt | 16 +++++++ .../defaultValues/lambdaInlining/thisClash.kt | 21 ++++++++++ .../lambdaInlining/thisClashInClass.kt | 23 ++++++++++ .../BlackBoxInlineCodegenTestGenerated.java | 42 +++++++++++++++++++ ...otlinAgainstInlineKotlinTestGenerated.java | 42 +++++++++++++++++++ 9 files changed, 230 insertions(+) create mode 100644 compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/receiverClash.kt create mode 100644 compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/receiverClash2.kt create mode 100644 compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/receiverClashInClass.kt create mode 100644 compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/receiverClashInClass2.kt create mode 100644 compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/simpleExtension.kt create mode 100644 compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/thisClash.kt create mode 100644 compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/thisClashInClass.kt diff --git a/compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/receiverClash.kt b/compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/receiverClash.kt new file mode 100644 index 00000000000..afd4250de8a --- /dev/null +++ b/compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/receiverClash.kt @@ -0,0 +1,19 @@ +// FILE: 1.kt +// LANGUAGE_VERSION: 1.2 +// SKIP_INLINE_CHECK_IN: inlineFun$default +package test + +inline fun String.inlineFun(crossinline lambda: () -> String = { this }): String { + return { + this + lambda() + }() +} + +// FILE: 2.kt + +import test.* + +fun box(): String { + val result = "OK".inlineFun() + return if (result == "OKOK") "OK" else "fail 1: $result" +} \ No newline at end of file diff --git a/compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/receiverClash2.kt b/compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/receiverClash2.kt new file mode 100644 index 00000000000..36dea8aea19 --- /dev/null +++ b/compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/receiverClash2.kt @@ -0,0 +1,21 @@ +// FILE: 1.kt +// LANGUAGE_VERSION: 1.2 +// SKIP_INLINE_CHECK_IN: inlineFun$default +package test + +inline fun String.inlineFun(crossinline lambda: () -> String, crossinline dlambda: () -> String = { this }): String { + return { + "${this} ${lambda()} ${dlambda()}" + }() +} + +// FILE: 2.kt + +import test.* + +fun String.test(): String = "INLINE".inlineFun({ this }) + +fun box(): String { + val result = "TEST".test() + return if (result == "INLINE TEST INLINE") "OK" else "fail 1: $result" +} \ No newline at end of file diff --git a/compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/receiverClashInClass.kt b/compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/receiverClashInClass.kt new file mode 100644 index 00000000000..1e04a87d68f --- /dev/null +++ b/compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/receiverClashInClass.kt @@ -0,0 +1,22 @@ +// FILE: 1.kt +// LANGUAGE_VERSION: 1.2 +// SKIP_INLINE_CHECK_IN: inlineFun$default +package test + +class A(val value: String) { + + inline fun String.inlineFun(crossinline lambda: () -> String = { this }): String { + return { + "$value ${this} ${lambda()}" + }() + } +} + +// FILE: 2.kt +//WITH_RUNTIME +import test.* + +fun box(): String { + val result = with(A("VALUE")) { "OK".inlineFun() } + return if (result == "VALUE OK OK") "OK" else "fail 1: $result" +} \ No newline at end of file diff --git a/compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/receiverClashInClass2.kt b/compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/receiverClashInClass2.kt new file mode 100644 index 00000000000..cdfae097655 --- /dev/null +++ b/compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/receiverClashInClass2.kt @@ -0,0 +1,24 @@ +// FILE: 1.kt +// LANGUAGE_VERSION: 1.2 +// SKIP_INLINE_CHECK_IN: inlineFun$default +package test + +class A(val value: String) { + + inline fun String.inlineFun(crossinline lambda: () -> String, crossinline dlambda: () -> String = { this }): String { + return { + "$value ${this} ${lambda()} ${dlambda()}" + }() + } +} + +// FILE: 2.kt +//WIH_RUNTIME +import test.* + +fun String.test(): String = with(A("VALUE")) { "INLINE".inlineFun({ this@test }) } + +fun box(): String { + val result = "TEST".test() + return if (result == "VALUE INLINE TEST INLINE") "OK" else "fail 1: $result" +} \ No newline at end of file diff --git a/compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/simpleExtension.kt b/compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/simpleExtension.kt new file mode 100644 index 00000000000..66e3f5133fb --- /dev/null +++ b/compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/simpleExtension.kt @@ -0,0 +1,16 @@ +// FILE: 1.kt +// LANGUAGE_VERSION: 1.2 +// SKIP_INLINE_CHECK_IN: inlineFun$default +package test + +inline fun inlineFun(param: String, lambda: String.() -> String = { this }): String { + return param.lambda() +} + +// FILE: 2.kt + +import test.* + +fun box(): String { + return inlineFun("OK") +} \ No newline at end of file diff --git a/compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/thisClash.kt b/compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/thisClash.kt new file mode 100644 index 00000000000..a58208961ee --- /dev/null +++ b/compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/thisClash.kt @@ -0,0 +1,21 @@ +// FILE: 1.kt +// LANGUAGE_VERSION: 1.2 +// SKIP_INLINE_CHECK_IN: inlineFun$default +package test + +inline fun String.inlineFun(crossinline lambda: () -> String = { { this }() }): String { + return { + { + this + lambda() + }() + }() +} + +// FILE: 2.kt + +import test.* + +fun box(): String { + val result = "OK".inlineFun() + return if (result == "OKOK") "OK" else "fail 1: $result" +} \ No newline at end of file diff --git a/compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/thisClashInClass.kt b/compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/thisClashInClass.kt new file mode 100644 index 00000000000..562b658c378 --- /dev/null +++ b/compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/thisClashInClass.kt @@ -0,0 +1,23 @@ +// FILE: 1.kt +// LANGUAGE_VERSION: 1.2 +// SKIP_INLINE_CHECK_IN: inlineFun$default +package test + +class A(val value: String) { + inline fun String.inlineFun(crossinline lambda: () -> String = { { this }() }): String { + return { + { + this + lambda() + }() + }() + } +} + +// FILE: 2.kt +//WITH_RUNTIME +import test.* + +fun box(): String { + val result = with(A("VALUE")) { "OK".inlineFun() } + return if (result == "OKOK") "OK" else "fail 1: $result" +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java index 8893f2b47c3..09a2fcc2128 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java @@ -997,6 +997,30 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo doTest(fileName); } + @TestMetadata("receiverClash.kt") + public void testReceiverClash() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/receiverClash.kt"); + doTest(fileName); + } + + @TestMetadata("receiverClash2.kt") + public void testReceiverClash2() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/receiverClash2.kt"); + doTest(fileName); + } + + @TestMetadata("receiverClashInClass.kt") + public void testReceiverClashInClass() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/receiverClashInClass.kt"); + doTest(fileName); + } + + @TestMetadata("receiverClashInClass2.kt") + public void testReceiverClashInClass2() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/receiverClashInClass2.kt"); + doTest(fileName); + } + @TestMetadata("simple.kt") public void testSimple() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/simple.kt"); @@ -1015,6 +1039,12 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo doTest(fileName); } + @TestMetadata("simpleExtension.kt") + public void testSimpleExtension() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/simpleExtension.kt"); + doTest(fileName); + } + @TestMetadata("simpleGeneric.kt") public void testSimpleGeneric() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/simpleGeneric.kt"); @@ -1027,6 +1057,18 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo doTest(fileName); } + @TestMetadata("thisClash.kt") + public void testThisClash() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/thisClash.kt"); + doTest(fileName); + } + + @TestMetadata("thisClashInClass.kt") + public void testThisClashInClass() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/thisClashInClass.kt"); + doTest(fileName); + } + @TestMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java index e6b77f77964..452d2b642c2 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java @@ -997,6 +997,30 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi doTest(fileName); } + @TestMetadata("receiverClash.kt") + public void testReceiverClash() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/receiverClash.kt"); + doTest(fileName); + } + + @TestMetadata("receiverClash2.kt") + public void testReceiverClash2() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/receiverClash2.kt"); + doTest(fileName); + } + + @TestMetadata("receiverClashInClass.kt") + public void testReceiverClashInClass() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/receiverClashInClass.kt"); + doTest(fileName); + } + + @TestMetadata("receiverClashInClass2.kt") + public void testReceiverClashInClass2() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/receiverClashInClass2.kt"); + doTest(fileName); + } + @TestMetadata("simple.kt") public void testSimple() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/simple.kt"); @@ -1015,6 +1039,12 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi doTest(fileName); } + @TestMetadata("simpleExtension.kt") + public void testSimpleExtension() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/simpleExtension.kt"); + doTest(fileName); + } + @TestMetadata("simpleGeneric.kt") public void testSimpleGeneric() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/simpleGeneric.kt"); @@ -1027,6 +1057,18 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi doTest(fileName); } + @TestMetadata("thisClash.kt") + public void testThisClash() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/thisClash.kt"); + doTest(fileName); + } + + @TestMetadata("thisClashInClass.kt") + public void testThisClashInClass() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/thisClashInClass.kt"); + doTest(fileName); + } + @TestMetadata("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)