Skip to content

Commit

Permalink
KT-42909 fix missing loop variable in 'withIndex' ranges
Browse files Browse the repository at this point in the history
  • Loading branch information
dnpetrov committed Nov 23, 2020
1 parent a9c9406 commit bf7fdcd
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 6 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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?) =
Expand Down Expand Up @@ -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().
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bf7fdcd

Please sign in to comment.