kotlin

Smart cast to 'X' is impossible, because 'X' is a public API property declared in different module


I have some code that looks like this

fun onMessage(message: Message) {
    message.property?.also {
        repository.updateProperty(message.property)
    }
}

where the parameter of updateProperty() is not nullable. The compiler gives an error:

Smart cast to 'Property' is impossible, because 'Message' is a public API property declared in different module

What is the best solution to solve this?


Solution

  • Turns out it was as easy as using it instead.

    fun onMessage(message: Message) {
        message.property?.also {
            repository.updateProperty(it)
        }
    }