diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineCodegenUtil.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineCodegenUtil.java index 6b10d56d06b..6d5d3672363 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineCodegenUtil.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineCodegenUtil.java @@ -443,4 +443,8 @@ public class InlineCodegenUtil { public static int getLoadStoreArgSize(int opcode) { return opcode == Opcodes.DSTORE || opcode == Opcodes.LSTORE || opcode == Opcodes.DLOAD || opcode == Opcodes.LLOAD ? 2 : 1; } + + public static boolean isStoreInstruction(int opcode) { + return opcode >= Opcodes.ISTORE && opcode <= Opcodes.ASTORE; + } } diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/LocalVarRemapper.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/LocalVarRemapper.java index 2ff2637222e..404d87c0e82 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/LocalVarRemapper.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/LocalVarRemapper.java @@ -114,7 +114,11 @@ public class LocalVarRemapper { StackValue value = remapInfo.value; if (value instanceof StackValue.Local) { if (remapInfo.parameterInfo != null) { - opcode = value.type.getOpcode(Opcodes.ILOAD); + //All remapped value parameters can't be rewritten except case of default ones. + //On remapping default parameter to actual value there is only one instruction that writes to it according to mask value + //but if such parameter remapped then it passed and this mask branch code never executed + //TODO add assertion about parameter default value: descriptor is required + opcode = value.type.getOpcode(InlineCodegenUtil.isStoreInstruction(opcode) ? Opcodes.ISTORE : Opcodes.ILOAD); } mv.visitVarInsn(opcode, ((StackValue.Local) value).index); if (remapInfo.parameterInfo != null) { diff --git a/compiler/testData/codegen/boxInline/defaultValues/defaultParamRemapping.1.kt b/compiler/testData/codegen/boxInline/defaultValues/defaultParamRemapping.1.kt new file mode 100644 index 00000000000..f4929184200 --- /dev/null +++ b/compiler/testData/codegen/boxInline/defaultValues/defaultParamRemapping.1.kt @@ -0,0 +1,9 @@ +import test.* + +fun box(): String { + val z = "OK".b { a, b -> + a + b + } + + return if (z == "s1OK") "OK" else "fail $z" +} \ No newline at end of file diff --git a/compiler/testData/codegen/boxInline/defaultValues/defaultParamRemapping.2.kt b/compiler/testData/codegen/boxInline/defaultValues/defaultParamRemapping.2.kt new file mode 100644 index 00000000000..5b81bd24492 --- /dev/null +++ b/compiler/testData/codegen/boxInline/defaultValues/defaultParamRemapping.2.kt @@ -0,0 +1,5 @@ +package test + +inline fun a(s1: String = "s1", s2: String = "s2", body: (a1: String, a2: String) -> String) = body(s1, s2) + +inline fun String.b(body: (a1: String, a2: String) -> String) = a(s2 = this, body = body) \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxInlineCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxInlineCodegenTestGenerated.java index 9792515275f..290c6642849 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxInlineCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxInlineCodegenTestGenerated.java @@ -274,6 +274,12 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo doTestMultiFileWithInlineCheck(fileName); } + @TestMetadata("defaultParamRemapping.1.kt") + public void testDefaultParamRemapping() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/defaultParamRemapping.1.kt"); + doTestMultiFileWithInlineCheck(fileName); + } + @TestMetadata("inlineInDefaultParameter.1.kt") public void testInlineInDefaultParameter() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/inlineInDefaultParameter.1.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/CompileKotlinAgainstInlineKotlinTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/CompileKotlinAgainstInlineKotlinTestGenerated.java index 66e597a9598..0e80b6a696a 100644 --- a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/CompileKotlinAgainstInlineKotlinTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/CompileKotlinAgainstInlineKotlinTestGenerated.java @@ -274,6 +274,12 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi doBoxTestWithInlineCheck(fileName); } + @TestMetadata("defaultParamRemapping.1.kt") + public void testDefaultParamRemapping() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/defaultParamRemapping.1.kt"); + doBoxTestWithInlineCheck(fileName); + } + @TestMetadata("inlineInDefaultParameter.1.kt") public void testInlineInDefaultParameter() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/inlineInDefaultParameter.1.kt");