Files
kotlin/compiler/testData/codegen/box/controlStructures/forInSequenceWithIndex/forInSequenceWithIndexThrowsCME.kt
2019-11-19 11:00:09 +03:00

26 lines
580 B
Kotlin
Vendored

// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM
// FULL_JDK
// WITH_RUNTIME
val xsl = arrayListOf("a", "b", "c", "d")
val xs = xsl.asSequence()
fun box(): String {
val s = StringBuilder()
var cmeThrown = false
try {
for ((index, x) in xs.withIndex()) {
s.append("$index:$x;")
xsl.clear()
}
} catch (e: java.util.ConcurrentModificationException) {
cmeThrown = true
}
if (!cmeThrown) return "Fail: CME should be thrown"
val ss = s.toString()
return if (ss == "0:a;") "OK" else "fail: '$ss'"
}