Files
kotlin/compiler/testData/diagnostics/tests/controlStructures/ForLoopWithExtensionIteratorOnNullable.kt
Dmitry Savvinov 816d89e393 [NI] Improved testdata after changes in applicabilities
This commits introduces testdata changes, where NI behaviour strictly
improved, after several previous fixes.

For some tests, just WITH_NEW_INFERENCE directive was added. It
indicates, that some of previous commits first introduced error in that
test, and then some other commit fixed it (netting no overall testdata
change). It is preferrably to keep those annotations until we will
migrate to NI completely, to prevent unexpected regressions.
2017-12-07 12:49:56 +03:00

23 lines
656 B
Kotlin
Vendored

// !WITH_NEW_INFERENCE
// 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_ON_NULLABLE!>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_ON_NULLABLE!>other<!>) {}
}