Hello. I have this code ``` private fun assertS...
# intellij
v
Hello. I have this code
Copy code
private fun assertSomething() {
        var count = 2
        if (count == 0) {
            error("field is empty")
        }
        runCatching {
            doSomeChecks()
        }.onFailure {
            refresh()
            count--
            assertSomething()
        }
    }
And IntelliJ IDEA has an inspection warning on
if (count == 0)
, saying that the condition is always
false
. I think it's a wrong warning, no? The
count
var will be equal to zero if the
doSomeChecks()
will fail twice.
s
The
count
variable is local to each individual function call. If you call the function again you get a new
count
with a new value.
v
Oh, indeed. Thank you!