Introduce FirForLoopChecker

This commit is contained in:
Mikhail Glukhikh
2021-04-02 13:19:04 +03:00
parent 4ddc0ed3fe
commit 2e14b65644
35 changed files with 708 additions and 118 deletions
@@ -1,22 +0,0 @@
// !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
<!UNSAFE_CALL!>for (s in container) {}<!>
}
class OtherContainer<K>(val k: K) {
operator fun iterator(): Iterator<K> = null!!
}
fun test2() {
val other: OtherContainer<String>? = null
// Error
<!UNSAFE_CALL!>for (s in other) {}<!>
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !WITH_NEW_INFERENCE
// See also KT-7428
class Container<K>(val k: K)
@@ -1,7 +1,7 @@
fun foo1() = <!EXPRESSION_EXPECTED!>while (b()) {}<!>
fun foo2() = <!UNRESOLVED_REFERENCE, UNRESOLVED_REFERENCE, UNRESOLVED_REFERENCE!>for (i in 10) {}<!>
fun foo2() = for (i in <!ITERATOR_MISSING!>10<!>) {}
fun foo3() = when (b()) {
true -> 1
@@ -8,7 +8,7 @@ class It {
}
fun test(c: Coll?) {
<!UNSAFE_CALL!>for (x in c) {}<!>
for (x in <!ITERATOR_ON_NULLABLE!>c<!>) {}
if (c != null) {
for(x in c) {}
@@ -8,5 +8,5 @@ class It {
}
fun test() {
<!UNSAFE_CALL, UNSAFE_CALL!>for (x in Coll()) {}<!>
for (x in <!HAS_NEXT_FUNCTION_NONE_APPLICABLE!>Coll()<!>) {}
}