diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java index 055a438ab4a..f70375fa169 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java @@ -627,7 +627,7 @@ public class ExpressionCodegen extends KtVisitor impleme // for (e : E in c) {...} protected final KtForExpression forExpression; - private final Label bodyStart = new Label(); + private final Label loopParameterStartLabel = new Label(); private final Label bodyEnd = new Label(); private final List leaveVariableTasks = Lists.newArrayList(); @@ -667,7 +667,7 @@ public class ExpressionCodegen extends KtVisitor impleme myFrameMap.leave(parameterDescriptor); v.visitLocalVariable(parameterDescriptor.getName().asString(), loopParameterType.getDescriptor(), null, - bodyStart, bodyEnd, + loopParameterStartLabel, bodyEnd, loopParameterVar); } }); @@ -687,9 +687,8 @@ public class ExpressionCodegen extends KtVisitor impleme public abstract void checkPreCondition(@NotNull Label loopExit); public void beforeBody() { - v.mark(bodyStart); - assignToLoopParameter(); + v.mark(loopParameterStartLabel); if (forExpression.getLoopParameter() == null) { KtDestructuringDeclaration multiParameter = forExpression.getDestructuringParameter(); diff --git a/compiler/testData/codegen/bytecodeText/forLoop/loopVarInterval.kt b/compiler/testData/codegen/bytecodeText/forLoop/loopVarInterval.kt new file mode 100644 index 00000000000..a7e06bcf379 --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/forLoop/loopVarInterval.kt @@ -0,0 +1,9 @@ +fun f() { + for (c in "123") { + print(c) + } +} + +// 1 ISTORE 0\s+L3 +// 1 ILOAD 0\s+INVOKEVIRTUAL java/io/PrintStream.print \(C\)V +// 1 LOCALVARIABLE c C L3 L8 0 diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java index 452c7cf441e..ef648a75a94 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java @@ -835,6 +835,12 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/bytecodeText/forLoop"), Pattern.compile("^(.+)\\.kt$"), true); } + @TestMetadata("loopVarInterval.kt") + public void testLoopVarInterval() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/forLoop/loopVarInterval.kt"); + doTest(fileName); + } + @TestMetadata("primitiveLiteralRange1.kt") public void testPrimitiveLiteralRange1() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/forLoop/primitiveLiteralRange1.kt");