Just wondering if the Kotlin Compiler (with Kotlin...
# kotlin-native
n
Just wondering if the Kotlin Compiler (with Kotlin 1.4.31) Smart Casting topicPtr into a non null one is correct behaviour? Below is some sample code:
Copy code
import kotlinx.cinterop.*
import platform.linux.free
import platform.linux.malloc

fun main() {
    var topicPtr = malloc(8uL * 5uL)?.reinterpret<ByteVar>()
    topicPtr?.set(0, '/'.toByte())
    topicPtr?.set(1, 't'.toByte())
    topicPtr?.set(2, 'e'.toByte())
    topicPtr?.set(3, 's'.toByte())
    topicPtr?.set(4, 't'.toByte())
    println("Topic: ${topicPtr?.toKString()}")
    free(topicPtr)
    topicPtr = null
    // Smart Casting occurs here.
    free(topicPtr)
    println("Exiting...")
}
d
Nahh, I'd say you should
!!
on the return value of malloc.
😱 1
What smart casting? Free takes a nullable argument.