For-loop now cannot use extension iterator on a nullable #KT-7428 Fixed

This commit is contained in:
Mikhail Glukhikh
2016-01-21 21:04:26 +03:00
parent 218dd41a08
commit 850dc89b38
9 changed files with 79 additions and 13 deletions
@@ -0,0 +1,21 @@
// See also KT-7428
class Container<K>(val k: K)
// iterator() must be an extension, otherwise code will not compile
operator fun <K> Container<K>.iterator(): Iterator<K> = null!!
fun test() {
val container: Container<String>? = null
// Error
container<!UNSAFE_CALL!>.<!>iterator()
// for extension iterator, this code compiles, but should not
for (s in <!ITERATOR_MISSING!>container<!>) {}
}
class OtherContainer<K>(val k: K) {
operator fun iterator(): Iterator<K> = null!!
}
fun test2() {
val other: OtherContainer<String>? = null
// Error
for (s in <!ITERATOR_MISSING!>other<!>) {}
}