diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/AnonymousObjectTransformer.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/AnonymousObjectTransformer.java index 2095b65da70..6c7f2ea0e66 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/AnonymousObjectTransformer.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/AnonymousObjectTransformer.java @@ -285,6 +285,8 @@ public class AnonymousObjectTransformer extends ObjectTransformer", constructorDescriptor, null, ArrayUtil.EMPTY_STRING_ARRAY); + final Label newBodyStartLabel = new Label(); + constructorVisitor.visitLabel(newBodyStartLabel); //initialize captured fields List newFieldsWithSkipped = TransformationUtilsKt.getNewFieldsToGenerate(allCapturedBuilder.listCaptured()); List fieldInfoWithSkipped = TransformationUtilsKt.transformToFieldInfo( @@ -318,7 +320,20 @@ public class AnonymousObjectTransformer extends ObjectTransformer", constructorDescriptor, null, ArrayUtil.EMPTY_STRING_ARRAY); + inlineMethodAndUpdateGlobalResult(parentRemapper, intermediateMethodNode, constructor, constructorInlineBuilder, true); + + AbstractInsnNode first = intermediateMethodNode.instructions.getFirst(); + final Label oldStartLabel = first instanceof LabelNode ? ((LabelNode) first).getLabel() : null; + intermediateMethodNode.accept(new MethodBodyVisitor(capturedFieldInitializer) { + @Override + public void visitLocalVariable(String name, String desc, String signature, Label start, Label end, int index) { + if (oldStartLabel == start) { + start = newBodyStartLabel;//patch for jack&jill + } + super.visitLocalVariable(name, desc, signature, start, end, index); + } + }); constructorVisitor.visitEnd(); AsmUtil.genClosureFields(TransformationUtilsKt.toNameTypePair(TransformationUtilsKt.filterSkipped(newFieldsWithSkipped)), classBuilder); } diff --git a/compiler/testData/codegen/bytecodeText/jackAndJill/inlinedConstuctor.kt b/compiler/testData/codegen/bytecodeText/jackAndJill/inlinedConstuctor.kt new file mode 100644 index 00000000000..e85435ace89 --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/jackAndJill/inlinedConstuctor.kt @@ -0,0 +1,10 @@ +public inline fun Iterable(crossinline iterator: () -> Iterator): Iterable = object : Iterable { + override fun iterator(): Iterator = iterator() +} + +public fun IntArray.asIterable(): Iterable { + return Iterable { this.iterator() } +} +/*Threre are two constuctors so we should be sure that we check required one by checking 'receiver$0$inlined' assign*/ +// 1 \(\[I\)V\s+L0\s+ALOAD 0\s+ALOAD 1\s+PUTFIELD InlinedConstuctorKt\$asIterable\$\$inlined\$Iterable\$1\.receiver\$0\$inlined : \[I +// 1 LOCALVARIABLE this LInlinedConstuctorKt\$asIterable\$\$inlined\$Iterable\$1; L0 L2 0 \ No newline at end of file diff --git a/compiler/testData/codegen/bytecodeText/jackAndJill/inlinedConstuctorWithSuperCallParams.kt b/compiler/testData/codegen/bytecodeText/jackAndJill/inlinedConstuctorWithSuperCallParams.kt new file mode 100644 index 00000000000..5ae3ef172b8 --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/jackAndJill/inlinedConstuctorWithSuperCallParams.kt @@ -0,0 +1,17 @@ +open class A(val z: String) { + +} + +inline fun test(crossinline s: () -> String) { + object : A("123") { + val x = s(); + } +} + +fun main(args: Array) { + var z = "123"; + test { z } +} + +/*Threre are two constuctors so we should be sure that we check LOCALVARIABLEs from same method*/ +// 1 LOCALVARIABLE this LInlinedConstuctorWithSuperCallParamsKt\$main\$\$inlined\$test\$1; L0 L7 0\s+LOCALVARIABLE \$super_call_param\$1 Ljava/lang/String; L0 L7 1