diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/MethodInliner.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/MethodInliner.java index 9c3896115ee..c2039205d47 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/MethodInliner.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/MethodInliner.java @@ -429,9 +429,11 @@ public class MethodInliner { String desc = methodInsnNode.desc; String name = methodInsnNode.name; //TODO check closure - int paramLength = Type.getArgumentsAndReturnSizes(desc) >> 2;//non static + Type[] argTypes = Type.getArgumentTypes(desc); + int paramCount = argTypes.length + 1;//non static + int firstParameterIndex = frame.getStackSize() - paramCount; if (isInvokeOnLambda(owner, name) /*&& methodInsnNode.owner.equals(INLINE_RUNTIME)*/) { - SourceValue sourceValue = frame.getStack(frame.getStackSize() - paramLength); + SourceValue sourceValue = frame.getStack(firstParameterIndex); LambdaInfo lambdaInfo = null; int varIndex = -1; @@ -450,18 +452,19 @@ public class MethodInliner { } else if (isAnonymousConstructorCall(owner, name)) { Map lambdaMapping = new HashMap(); - int paramStart = frame.getStackSize() - paramLength; - for (int i = 0; i < paramLength; i++) { - SourceValue sourceValue = frame.getStack(paramStart + i); + int offset = 0; + for (int i = 0; i < paramCount; i++) { + SourceValue sourceValue = frame.getStack(firstParameterIndex + i); if (sourceValue.insns.size() == 1) { AbstractInsnNode insnNode = sourceValue.insns.iterator().next(); LambdaInfo lambdaInfo = getLambdaIfExists(insnNode); if (lambdaInfo != null) { - lambdaMapping.put(i, lambdaInfo); + lambdaMapping.put(offset, lambdaInfo); node.instructions.remove(insnNode); } } + offset += i == 0 ? 1 : argTypes[i - 1].getSize(); } anonymousObjectGenerations.add( diff --git a/compiler/testData/codegen/boxInline/anonymousObject/kt9877.1.kt b/compiler/testData/codegen/boxInline/anonymousObject/kt9877.1.kt new file mode 100644 index 00000000000..5dd5af720e7 --- /dev/null +++ b/compiler/testData/codegen/boxInline/anonymousObject/kt9877.1.kt @@ -0,0 +1,18 @@ +import test.* + +fun box(): String { + val loci = listOf("a", "b", "c") + var gene = "g1" + + inlineCall { + val value = 10.0 + loci.forEach { + var locusMap = 1.0 + { + locusMap = value + gene = "OK" + }() + } + } + return gene +} diff --git a/compiler/testData/codegen/boxInline/anonymousObject/kt9877.2.kt b/compiler/testData/codegen/boxInline/anonymousObject/kt9877.2.kt new file mode 100644 index 00000000000..4fab92c98bd --- /dev/null +++ b/compiler/testData/codegen/boxInline/anonymousObject/kt9877.2.kt @@ -0,0 +1,10 @@ +package test + +fun T.noInline(p: (T) -> Unit) { + p(this) +} + +inline fun inlineCall(p: () -> Unit) { + p() +} + diff --git a/compiler/testData/codegen/boxInline/anonymousObject/kt9877_2.1.kt b/compiler/testData/codegen/boxInline/anonymousObject/kt9877_2.1.kt new file mode 100644 index 00000000000..c570bab3c31 --- /dev/null +++ b/compiler/testData/codegen/boxInline/anonymousObject/kt9877_2.1.kt @@ -0,0 +1,17 @@ +import test.* + +fun box(): String { + var gene = "g1" + + inlineCall { + val value = 10.0 + inlineCall { + { + value + gene = "OK" + }() + } + } + + return gene +} diff --git a/compiler/testData/codegen/boxInline/anonymousObject/kt9877_2.2.kt b/compiler/testData/codegen/boxInline/anonymousObject/kt9877_2.2.kt new file mode 100644 index 00000000000..7f94c43e241 --- /dev/null +++ b/compiler/testData/codegen/boxInline/anonymousObject/kt9877_2.2.kt @@ -0,0 +1,6 @@ +package test + +inline fun inlineCall(p: () -> Unit) { + p() +} + diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxCodegenTestGenerated.java index f080547b390..f9b23efc1bf 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxCodegenTestGenerated.java @@ -2712,24 +2712,24 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { @RunWith(JUnit3RunnerWithInners.class) public static class Convention extends AbstractBlackBoxCodegenTest { public void testAllFilesPresentInConvention() throws Exception { - JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/defaultArguments/convention"), Pattern.compile("^(.+)\\.kt$"), true); + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/defaultArguments/convention"), Pattern.compile("^(.+)\\.kt$"), true); } @TestMetadata("incWithDefaultInGetter.kt") public void testIncWithDefaultInGetter() throws Exception { - String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/defaultArguments/convention/incWithDefaultInGetter.kt"); + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/defaultArguments/convention/incWithDefaultInGetter.kt"); doTest(fileName); } @TestMetadata("kt9140.kt") public void testKt9140() throws Exception { - String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/defaultArguments/convention/kt9140.kt"); + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/defaultArguments/convention/kt9140.kt"); doTest(fileName); } @TestMetadata("plusAssignWithDefaultInGetter.kt") public void testPlusAssignWithDefaultInGetter() throws Exception { - String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/defaultArguments/convention/plusAssignWithDefaultInGetter.kt"); + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/defaultArguments/convention/plusAssignWithDefaultInGetter.kt"); doTest(fileName); } } @@ -6427,18 +6427,18 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { @RunWith(JUnit3RunnerWithInners.class) public static class Private extends AbstractBlackBoxCodegenTest { public void testAllFilesPresentInPrivate() throws Exception { - JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/private"), Pattern.compile("^(.+)\\.kt$"), true); + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/private"), Pattern.compile("^(.+)\\.kt$"), true); } @TestMetadata("arrayConvention.kt") public void testArrayConvention() throws Exception { - String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/private/arrayConvention.kt"); + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/private/arrayConvention.kt"); doTest(fileName); } @TestMetadata("kt9855.kt") public void testKt9855() throws Exception { - String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/private/kt9855.kt"); + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/private/kt9855.kt"); doTest(fileName); } } diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxInlineCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxInlineCodegenTestGenerated.java index 8061ae8341f..653e497eb95 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxInlineCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxInlineCodegenTestGenerated.java @@ -138,6 +138,18 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/anonymousObject/kt9064v2.1.kt"); doTestMultiFileWithInlineCheck(fileName); } + + @TestMetadata("kt9877.1.kt") + public void testKt9877() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/anonymousObject/kt9877.1.kt"); + doTestMultiFileWithInlineCheck(fileName); + } + + @TestMetadata("kt9877_2.1.kt") + public void testKt9877_2() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/anonymousObject/kt9877_2.1.kt"); + doTestMultiFileWithInlineCheck(fileName); + } } @TestMetadata("compiler/testData/codegen/boxInline/argumentOrder") diff --git a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/CompileKotlinAgainstInlineKotlinTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/CompileKotlinAgainstInlineKotlinTestGenerated.java index c8bd7af91bb..24d99b97e6f 100644 --- a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/CompileKotlinAgainstInlineKotlinTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/CompileKotlinAgainstInlineKotlinTestGenerated.java @@ -138,6 +138,18 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/anonymousObject/kt9064v2.1.kt"); doBoxTestWithInlineCheck(fileName); } + + @TestMetadata("kt9877.1.kt") + public void testKt9877() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/anonymousObject/kt9877.1.kt"); + doBoxTestWithInlineCheck(fileName); + } + + @TestMetadata("kt9877_2.1.kt") + public void testKt9877_2() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/anonymousObject/kt9877_2.1.kt"); + doBoxTestWithInlineCheck(fileName); + } } @TestMetadata("compiler/testData/codegen/boxInline/argumentOrder")