How come Kotlin contracts are not working anymore?...
# getting-started
j
How come Kotlin contracts are not working anymore? These have been working fine a few months back.
r
Interesting. I don't think that's ever worked for me. Because
channel
is a class property, it could have mutated between the
requireNotNull
and usage. I usually need to do:
Copy code
val channel = requireNotNull(this.channel)
<http://channel.cd|channel.cd>(..)


//or
channel.?let { // use }
👍 1
j
I usually do that ?.let pattern also. But it doesn't always end in the cleanest code. I did use the contracts like shown on the image some months ago. So there is something that has changed. But yeah, I will go ahead and do
val channel = requireNotNull(this.channel)
instead of having
!!
all the time 🙂
e
smart casting should work on non-captured locals,
Copy code
fun foo() {
    var bar: Int?
    bar = 1
    println(bar.inc())
}
but you can't prove that class properties won't be mutated by anybody else