Given this:
inline fun String?.isNotNull() : Boolean = this != null
We get…
private fun test() {
val test = someCallThatCanReturnANullString();
if (test != null) {
test.replaceFirst("hmm", "it works!")
}
if (test.isNotNull()) {
test.replaceFirst("hmm", "Nope! Compiler error despite the inline fun!")
}
}
I’m new to Kotlin and perhaps missing something but I would expect that given this is an inline fun
and thus can’t be runtime replaced, it should be possible for the compiler to determine that test
is safely null
checked. Is this a limitation of the compiler? Is there a reason why it shouldn’t recognize this?