From 4f914fafcaac6530300a16dc78759610de056754 Mon Sep 17 00:00:00 2001 From: Mikhael Bogdanov Date: Wed, 28 Jun 2017 14:22:34 +0200 Subject: [PATCH] Calculate default mask shift properly #KT-18689 Fixed --- .../kotlin/codegen/inline/InlineCodegen.kt | 4 ++- .../callableReference/bound/mixed.kt | 23 ++++++++++++++ .../boxInline/defaultValues/kt18689.kt | 21 +++++++++++++ .../boxInline/defaultValues/kt18689_2.kt | 21 +++++++++++++ .../boxInline/defaultValues/kt18689_3.kt | 21 +++++++++++++ .../boxInline/defaultValues/kt18689_4.kt | 21 +++++++++++++ .../IrBlackBoxInlineCodegenTestGenerated.java | 30 +++++++++++++++++++ ...otlinAgainstInlineKotlinTestGenerated.java | 30 +++++++++++++++++++ .../BlackBoxInlineCodegenTestGenerated.java | 30 +++++++++++++++++++ ...otlinAgainstInlineKotlinTestGenerated.java | 30 +++++++++++++++++++ ...CallableReferenceInlineTestsGenerated.java | 6 ++++ .../InlineDefaultValuesTestsGenerated.java | 24 +++++++++++++++ 12 files changed, 260 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/codegen/boxInline/callableReference/bound/mixed.kt create mode 100644 compiler/testData/codegen/boxInline/defaultValues/kt18689.kt create mode 100644 compiler/testData/codegen/boxInline/defaultValues/kt18689_2.kt create mode 100644 compiler/testData/codegen/boxInline/defaultValues/kt18689_3.kt create mode 100644 compiler/testData/codegen/boxInline/defaultValues/kt18689_4.kt diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineCodegen.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineCodegen.kt index bc4b3772edf..f6ff212108c 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineCodegen.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineCodegen.kt @@ -366,7 +366,9 @@ abstract class InlineCodegen( assert(constantValue is Int) { "Mask should be of Integer type, but " + constantValue } maskValues.add(constantValue as Int) if (maskStartIndex == -1) { - maskStartIndex = invocationParamBuilder.nextParameterOffset + maskStartIndex = invocationParamBuilder.listAllParams().sumBy { + if (it is CapturedParamInfo) 0 else it.type.size + } } } else { diff --git a/compiler/testData/codegen/boxInline/callableReference/bound/mixed.kt b/compiler/testData/codegen/boxInline/callableReference/bound/mixed.kt new file mode 100644 index 00000000000..426984d7d1e --- /dev/null +++ b/compiler/testData/codegen/boxInline/callableReference/bound/mixed.kt @@ -0,0 +1,23 @@ +// FILE: 1.kt + +package test + +class Foo { + fun foo() = "OK" + fun foo2() = "OK2" +} + +inline fun inlineFn(a: String, crossinline fn: () -> String, x: Long = 1, crossinline fn2: () -> String, c: String): String { + return a + fn() + x + fn2() + c +} + +// FILE: 2.kt + +import test.* + +private val foo = Foo() + +fun box(): String { + val result = inlineFn("a", foo::foo, 5, foo::foo2, "end") + return if (result == "aOK5OK2end") "OK" else "fail: $result" +} \ No newline at end of file diff --git a/compiler/testData/codegen/boxInline/defaultValues/kt18689.kt b/compiler/testData/codegen/boxInline/defaultValues/kt18689.kt new file mode 100644 index 00000000000..f64cd2306d2 --- /dev/null +++ b/compiler/testData/codegen/boxInline/defaultValues/kt18689.kt @@ -0,0 +1,21 @@ +// FILE: 1.kt + +package test + +class Foo { + fun foo() = "OK" +} + +inline fun inlineFn(crossinline fn: () -> String, x: Int? = 1): String { + return fn() +} + +// FILE: 2.kt + +import test.* + +private val foo = Foo() + +fun box(): String { + return inlineFn(foo::foo) +} \ No newline at end of file diff --git a/compiler/testData/codegen/boxInline/defaultValues/kt18689_2.kt b/compiler/testData/codegen/boxInline/defaultValues/kt18689_2.kt new file mode 100644 index 00000000000..5ad6a07bf34 --- /dev/null +++ b/compiler/testData/codegen/boxInline/defaultValues/kt18689_2.kt @@ -0,0 +1,21 @@ +// FILE: 1.kt + +package test + +class Foo { + fun foo() = "O" +} + +inline fun inlineFn(crossinline fn: () -> String, x: String = "K"): String { + return fn() + x +} + +// FILE: 2.kt + +import test.* + +private val foo = Foo() + +fun box(): String { + return inlineFn(foo::foo) +} \ No newline at end of file diff --git a/compiler/testData/codegen/boxInline/defaultValues/kt18689_3.kt b/compiler/testData/codegen/boxInline/defaultValues/kt18689_3.kt new file mode 100644 index 00000000000..137eaa4138d --- /dev/null +++ b/compiler/testData/codegen/boxInline/defaultValues/kt18689_3.kt @@ -0,0 +1,21 @@ +// FILE: 1.kt + +package test + +class Foo { + fun foo() = "O" +} + +inline fun inlineFn(crossinline fn: () -> String, x: String = "X"): String { + return fn() + x +} + +// FILE: 2.kt + +import test.* + +private val foo = Foo() + +fun box(): String { + return inlineFn(foo::foo, "K") +} \ No newline at end of file diff --git a/compiler/testData/codegen/boxInline/defaultValues/kt18689_4.kt b/compiler/testData/codegen/boxInline/defaultValues/kt18689_4.kt new file mode 100644 index 00000000000..23c19b4b11d --- /dev/null +++ b/compiler/testData/codegen/boxInline/defaultValues/kt18689_4.kt @@ -0,0 +1,21 @@ +// FILE: 1.kt + +package test + +class Foo { + fun foo() = "OK" +} + +inline fun inlineFn(crossinline fn: () -> String, x: Long = 1L): String { + return fn() +} + +// FILE: 2.kt + +import test.* + +private val foo = Foo() + +fun box(): String { + return inlineFn(foo::foo) +} \ No newline at end of file diff --git a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java index 4bebd427c58..b73827124ad 100644 --- a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java +++ b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java @@ -742,6 +742,12 @@ public class IrBlackBoxInlineCodegenTestGenerated extends AbstractIrBlackBoxInli doTest(fileName); } + @TestMetadata("mixed.kt") + public void testMixed() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/callableReference/bound/mixed.kt"); + doTest(fileName); + } + @TestMetadata("objectProperty.kt") public void testObjectProperty() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/callableReference/bound/objectProperty.kt"); @@ -983,6 +989,30 @@ public class IrBlackBoxInlineCodegenTestGenerated extends AbstractIrBlackBoxInli doTest(fileName); } + @TestMetadata("kt18689.kt") + public void testKt18689() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/kt18689.kt"); + doTest(fileName); + } + + @TestMetadata("kt18689_2.kt") + public void testKt18689_2() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/kt18689_2.kt"); + doTest(fileName); + } + + @TestMetadata("kt18689_3.kt") + public void testKt18689_3() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/kt18689_3.kt"); + doTest(fileName); + } + + @TestMetadata("kt18689_4.kt") + public void testKt18689_4() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/kt18689_4.kt"); + doTest(fileName); + } + @TestMetadata("kt5685.kt") public void testKt5685() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/kt5685.kt"); diff --git a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrCompileKotlinAgainstInlineKotlinTestGenerated.java b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrCompileKotlinAgainstInlineKotlinTestGenerated.java index 93a51f28795..e73262c5172 100644 --- a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrCompileKotlinAgainstInlineKotlinTestGenerated.java +++ b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrCompileKotlinAgainstInlineKotlinTestGenerated.java @@ -742,6 +742,12 @@ public class IrCompileKotlinAgainstInlineKotlinTestGenerated extends AbstractIrC doTest(fileName); } + @TestMetadata("mixed.kt") + public void testMixed() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/callableReference/bound/mixed.kt"); + doTest(fileName); + } + @TestMetadata("objectProperty.kt") public void testObjectProperty() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/callableReference/bound/objectProperty.kt"); @@ -983,6 +989,30 @@ public class IrCompileKotlinAgainstInlineKotlinTestGenerated extends AbstractIrC doTest(fileName); } + @TestMetadata("kt18689.kt") + public void testKt18689() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/kt18689.kt"); + doTest(fileName); + } + + @TestMetadata("kt18689_2.kt") + public void testKt18689_2() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/kt18689_2.kt"); + doTest(fileName); + } + + @TestMetadata("kt18689_3.kt") + public void testKt18689_3() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/kt18689_3.kt"); + doTest(fileName); + } + + @TestMetadata("kt18689_4.kt") + public void testKt18689_4() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/kt18689_4.kt"); + doTest(fileName); + } + @TestMetadata("kt5685.kt") public void testKt5685() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/kt5685.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java index 9bca40efdcf..e152f704d17 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java @@ -742,6 +742,12 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo doTest(fileName); } + @TestMetadata("mixed.kt") + public void testMixed() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/callableReference/bound/mixed.kt"); + doTest(fileName); + } + @TestMetadata("objectProperty.kt") public void testObjectProperty() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/callableReference/bound/objectProperty.kt"); @@ -983,6 +989,30 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo doTest(fileName); } + @TestMetadata("kt18689.kt") + public void testKt18689() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/kt18689.kt"); + doTest(fileName); + } + + @TestMetadata("kt18689_2.kt") + public void testKt18689_2() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/kt18689_2.kt"); + doTest(fileName); + } + + @TestMetadata("kt18689_3.kt") + public void testKt18689_3() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/kt18689_3.kt"); + doTest(fileName); + } + + @TestMetadata("kt18689_4.kt") + public void testKt18689_4() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/kt18689_4.kt"); + doTest(fileName); + } + @TestMetadata("kt5685.kt") public void testKt5685() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/kt5685.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java index 87314ee4e4f..aa572518dd4 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java @@ -742,6 +742,12 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi doTest(fileName); } + @TestMetadata("mixed.kt") + public void testMixed() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/callableReference/bound/mixed.kt"); + doTest(fileName); + } + @TestMetadata("objectProperty.kt") public void testObjectProperty() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/callableReference/bound/objectProperty.kt"); @@ -983,6 +989,30 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi doTest(fileName); } + @TestMetadata("kt18689.kt") + public void testKt18689() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/kt18689.kt"); + doTest(fileName); + } + + @TestMetadata("kt18689_2.kt") + public void testKt18689_2() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/kt18689_2.kt"); + doTest(fileName); + } + + @TestMetadata("kt18689_3.kt") + public void testKt18689_3() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/kt18689_3.kt"); + doTest(fileName); + } + + @TestMetadata("kt18689_4.kt") + public void testKt18689_4() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/kt18689_4.kt"); + doTest(fileName); + } + @TestMetadata("kt5685.kt") public void testKt5685() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/kt5685.kt"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/CallableReferenceInlineTestsGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/CallableReferenceInlineTestsGenerated.java index 619b2035a61..2e36f110bb7 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/CallableReferenceInlineTestsGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/CallableReferenceInlineTestsGenerated.java @@ -146,6 +146,12 @@ public class CallableReferenceInlineTestsGenerated extends AbstractCallableRefer doTest(fileName); } + @TestMetadata("mixed.kt") + public void testMixed() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/callableReference/bound/mixed.kt"); + doTest(fileName); + } + @TestMetadata("objectProperty.kt") public void testObjectProperty() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/callableReference/bound/objectProperty.kt"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/InlineDefaultValuesTestsGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/InlineDefaultValuesTestsGenerated.java index e9df9a5aa3f..777d73b4856 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/InlineDefaultValuesTestsGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/InlineDefaultValuesTestsGenerated.java @@ -96,6 +96,30 @@ public class InlineDefaultValuesTestsGenerated extends AbstractInlineDefaultValu doTest(fileName); } + @TestMetadata("kt18689.kt") + public void testKt18689() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/kt18689.kt"); + doTest(fileName); + } + + @TestMetadata("kt18689_2.kt") + public void testKt18689_2() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/kt18689_2.kt"); + doTest(fileName); + } + + @TestMetadata("kt18689_3.kt") + public void testKt18689_3() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/kt18689_3.kt"); + doTest(fileName); + } + + @TestMetadata("kt18689_4.kt") + public void testKt18689_4() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/kt18689_4.kt"); + doTest(fileName); + } + @TestMetadata("kt5685.kt") public void testKt5685() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/kt5685.kt");