I have a project that is using Jetpack compose. After I switched to the later version of kotlinCompilerExtensionVersion I had a problem: part of the composition wasn't drawn anymore.
I found out that the problem was with a code similar to this one:
variable?.let {
ComposableFunction1(it)
} ?: ComposableFunction2()
You can reproduce the issue creating a new Compose project using the wizard and replacing the Greeting function with:
@Composable
fun Greeting(name: String?) {
name?.let {
Text(text = "Hello $it!")
} ?: Text(text = "Hello!")
}
If I use the old version 1.0.5 for both Compose and the kotlinCompilerExtension and the version 1.5.31 of Kotlin, everything works. If I switch to kotlinCompilerExtension 1.1.0-rc02 and Kotlin 1.6.0 the Text(text = "Hello!") does not run.
Of course I can fix the issue using if-else instead the (convoluted) let + elvis operator but I wanted to understand whether the new behaviour is documented somewhere.
By the way, if I add the function:
private fun testFunction(name: String?) {
name?.let {
Log.d("testFunction", "Hello $it!")
} ?: Log.d("testFunction", "Name is null")
}
everything works as expected even with Kotlin 1.6.0 that means that I see the log "Name is null"