arrayIterators: Restore index to the previous value after NoSuchElementException has been thrown

Relates to #KT-17453
This commit is contained in:
Ilya Gorbunov
2017-04-18 21:45:17 +03:00
parent 731dcf5d6f
commit a87da4338f
3 changed files with 10 additions and 10 deletions
@@ -29,7 +29,7 @@ class GenerateArrayIterators(out: PrintWriter) : BuiltInsSourceGenerator(out) {
out.println("private class Array${s}Iterator(private val array: ${s}Array) : ${s}Iterator() {")
out.println(" private var index = 0")
out.println(" override fun hasNext() = index < array.size")
out.println(" override fun next$s() = try { array[index++] } catch (e: ArrayIndexOutOfBoundsException) { throw NoSuchElementException(e.message) }")
out.println(" override fun next$s() = try { array[index++] } catch (e: ArrayIndexOutOfBoundsException) { index -= 1; throw NoSuchElementException(e.message) }")
out.println("}")
out.println()
}