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
@@ -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().