diff --git a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java index 61ddd00b119..fc3fc9a4d51 100644 --- a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java @@ -22755,6 +22755,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT public void testForInWithIndexWithIndex() throws Exception { runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInWithIndexWithIndex.kt"); } + + @TestMetadata("kt42909.kt") + public void testKt42909() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/kt42909.kt"); + } } @TestMetadata("compiler/testData/codegen/box/ranges/forInReversed") diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/loops/HeaderProcessor.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/loops/HeaderProcessor.kt index 0300e61cc9e..321b3429224 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/loops/HeaderProcessor.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/loops/HeaderProcessor.kt @@ -297,7 +297,7 @@ internal class ProgressionLoopHeader( // loopVariable = inductionVariable // inductionVariable = inductionVariable + step - listOfNotNull(loopVariable, incrementInductionVariable(this)) + listOfNotNull(this@ProgressionLoopHeader.loopVariable, incrementInductionVariable(this)) } override fun buildLoop(builder: DeclarationIrBuilder, oldLoop: IrLoop, newBody: IrExpression?) = @@ -552,11 +552,8 @@ internal class WithIndexLoopHeader( // // We "wire" the 1st destructured component to index, and the 2nd to the loop variable value from the underlying iterable. loopVariableComponents[1]?.initializer = irGet(indexVariable) - listOfNotNull(loopVariableComponents[1], incrementIndexStatement) + nestedLoopHeader.initializeIteration( - loopVariableComponents[2], - linkedMapOf(), - builder - ) + listOfNotNull(loopVariableComponents[1], incrementIndexStatement) + + nestedLoopHeader.initializeIteration(loopVariableComponents[2], linkedMapOf(), builder) } // Use the nested loop header to build the loop. More info in comments in initializeIteration(). diff --git a/compiler/testData/codegen/box/ranges/forInProgressionWithIndex/kt42909.kt b/compiler/testData/codegen/box/ranges/forInProgressionWithIndex/kt42909.kt new file mode 100644 index 00000000000..3994b61ed58 --- /dev/null +++ b/compiler/testData/codegen/box/ranges/forInProgressionWithIndex/kt42909.kt @@ -0,0 +1,16 @@ +// WITH_RUNTIME +// KJS_WITH_FULL_RUNTIME + +fun box(): String { + var r = test() + if (r != "01") throw AssertionError(r.toString()) + return "OK" +} + +private fun test(): String { + var r = "" + for ((i, _) in (1..'c' - 'a').withIndex()) { + r += i.toString() + } + return r +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index fa369720281..2507d84c0ab 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -24526,6 +24526,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { public void testForInWithIndexWithIndex() throws Exception { runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInWithIndexWithIndex.kt"); } + + @TestMetadata("kt42909.kt") + public void testKt42909() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/kt42909.kt"); + } } @TestMetadata("compiler/testData/codegen/box/ranges/forInReversed") diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 6cbd283fad3..1b0a7860b6a 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -24526,6 +24526,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes public void testForInWithIndexWithIndex() throws Exception { runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInWithIndexWithIndex.kt"); } + + @TestMetadata("kt42909.kt") + public void testKt42909() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/kt42909.kt"); + } } @TestMetadata("compiler/testData/codegen/box/ranges/forInReversed") diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index 11dd8f2ffc8..9e5864a4ad4 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -22755,6 +22755,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes public void testForInWithIndexWithIndex() throws Exception { runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInWithIndexWithIndex.kt"); } + + @TestMetadata("kt42909.kt") + public void testKt42909() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/kt42909.kt"); + } } @TestMetadata("compiler/testData/codegen/box/ranges/forInReversed") diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java index 0ef28c60d79..ded22676945 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java @@ -18946,6 +18946,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes public void testForInWithIndexWithIndex() throws Exception { runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInWithIndexWithIndex.kt"); } + + @TestMetadata("kt42909.kt") + public void testKt42909() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/kt42909.kt"); + } } @TestMetadata("compiler/testData/codegen/box/ranges/forInReversed") diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java index 8ac0f210150..f4943aebaf4 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java @@ -18946,6 +18946,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { public void testForInWithIndexWithIndex() throws Exception { runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInWithIndexWithIndex.kt"); } + + @TestMetadata("kt42909.kt") + public void testKt42909() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/kt42909.kt"); + } } @TestMetadata("compiler/testData/codegen/box/ranges/forInReversed") diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java index c5f9692f93b..18ef3e5b394 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java @@ -19051,6 +19051,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { public void testForInWithIndexWithIndex() throws Exception { runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/forInWithIndexWithIndex.kt"); } + + @TestMetadata("kt42909.kt") + public void testKt42909() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/kt42909.kt"); + } } @TestMetadata("compiler/testData/codegen/box/ranges/forInReversed") diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java index 2e47c7a0607..5d69afc5888 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java @@ -11807,6 +11807,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest public void testAllFilesPresentInForInProgressionWithIndex() throws Exception { KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/ranges/forInProgressionWithIndex"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.WASM, true); } + + @TestMetadata("kt42909.kt") + public void testKt42909() throws Exception { + runTest("compiler/testData/codegen/box/ranges/forInProgressionWithIndex/kt42909.kt"); + } } @TestMetadata("compiler/testData/codegen/box/ranges/forInReversed")