KT-531 Support nullable iterator in for()

This commit is contained in:
Alex Tkachman
2011-11-18 21:12:25 +02:00
parent 50edc9750b
commit 39ca8eded8
5 changed files with 61 additions and 12 deletions
@@ -12,5 +12,10 @@ fun box() : String {
System.out?.println(sum)
if(sum != 10) return "b failed"
val d : Array<Int?>? = null
for (el in d) {
sum = sum + (el ?: 7)
}
return "OK"
}
@@ -10,5 +10,10 @@ fun box() : String {
}
if(sum != 10) return "a failed"
val b : IntArray? = null
for (el in b) {
sum = sum + el
}
return "OK"
}
@@ -66,6 +66,14 @@ fun box() : String {
System.out?.println(sum)
if(sum != 10) return "b failed"
val c7 = MyCollection5()
sum = 0
for (el in c7) {
sum = sum + el
}
if(sum != 0) return "c7 failed"
return "OK"
}
@@ -115,3 +123,14 @@ class MyCollection4() {
fun hasNext() = k > 0
}
}
class MyCollection5() {
fun iterator() : MyIterator? = null
class MyIterator() {
var k : Int = 5
fun next() : Int = k--
fun hasNext() = k > 0
}
}