KT-42909 fix missing loop variable in 'withIndex' ranges

This commit is contained in:
Dmitry Petrov
2020-11-23 10:46:42 +03:00
parent a9c9406a55
commit bf7fdcda6e
10 changed files with 59 additions and 6 deletions
@@ -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")
@@ -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().
@@ -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
}
@@ -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")
@@ -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")
@@ -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")
@@ -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")
@@ -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")
@@ -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")
@@ -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")