JVM IR: Start fake variables for default lambdas after initialization

KT-52702
This commit is contained in:
Steven Schäfer
2022-06-09 14:05:50 +02:00
committed by Alexander Udalov
parent 08f18c2940
commit 194a1d1c6a
10 changed files with 73 additions and 4 deletions
@@ -140,12 +140,11 @@ class DefaultLambda(info: ExtractedDefaultLambda, sourceCompiler: SourceCompiler
val withFakeVariable =
MethodNode(originNode.access, originNode.name, originNode.desc, originNode.signature, originNode.exceptions?.toTypedArray())
val fakeVarIndex = originNode.maxLocals
withFakeVariable.instructions.add(LdcInsnNode(0))
withFakeVariable.instructions.add(VarInsnNode(Opcodes.ISTORE, fakeVarIndex))
val startLabel = LabelNode().also { withFakeVariable.instructions.add(it) }
originNode.accept(withFakeVariable)
val startLabel =
withFakeVariable.instructions.first as? LabelNode ?: LabelNode().apply { withFakeVariable.instructions.insert(this) }
val endLabel = withFakeVariable.instructions.last as? LabelNode ?: LabelNode().apply { withFakeVariable.instructions.add(this) }
withFakeVariable.instructions.insert(startLabel, VarInsnNode(Opcodes.ISTORE, fakeVarIndex))
withFakeVariable.instructions.insert(startLabel, LdcInsnNode(0))
withFakeVariable.localVariables.add(
LocalVariableNode(