FirForLoopChecker: report also OPERATOR_MODIFIER if appropriate + minor

This commits checks iterator/hasNext/next functions whether they are
declared as operator or not. Also, it changes logic of hasNext/next
error reporting, now we're able to report errors about both these
functions.
This commit is contained in:
Mikhail Glukhikh
2021-04-16 15:24:16 +03:00
parent 2e14b65644
commit a736d62edd
16 changed files with 222 additions and 52 deletions
+28 -1
View File
@@ -111,4 +111,31 @@ fun test2() {
Anc() + Anc()
Anc() <!OPERATOR_MODIFIER_REQUIRED!>-<!> Anc()
Anc2() + Anc2()
}
}
fun Int.iterator(): MyIntIterator = null!!
operator fun Double.iterator(): MyDoubleIterator = null!!
operator fun Boolean.iterator(): MyBooleanIterator = null!!
interface MyIntIterator {
operator fun hasNext(): Boolean
operator fun next(): Int
}
interface MyDoubleIterator {
operator fun hasNext(): Boolean
fun next(): Double
}
interface MyBooleanIterator {
fun hasNext(): Boolean
operator fun next(): Boolean
}
fun test3(i: Int, d: Double, b: Boolean) {
for (element in <!OPERATOR_MODIFIER_REQUIRED!>i<!>) {}
for (element in <!OPERATOR_MODIFIER_REQUIRED!>d<!>) {}
for (element in <!OPERATOR_MODIFIER_REQUIRED!>b<!>) {}
}