This code caused Kotlin compiler backend to fail. I’m using Kotlin 1.3.61 with Jetpack Compose 0.1.0-dev03. The affected function:
@Composable
private fun RandomActivityButton() {
lateinit var onClickNormal: () -> Unit
lateinit var onClick: State<() -> Unit>
onClickNormal = {
val intent = Intent(
this@MainActivity,
ActivityDescriptionActivity::class.java
)
val activity = mainScope.async(Dispatchers.IO) {
//BoredApi().randomAsync().await()
BoredApi().byCriterionsAsync { Key set 6509779 }.await()
}
onClick.value = {}
mainScope.launch {
intent.putExtra("activity", activity.await())
startActivity(intent)
onClick.value = onClickNormal
}
}
onClick = +state { onClickNormal }
Button(
text = "navigate",
onClick = onClick.value
)
}
./gradlew build
output: 123 · GitHub
I can provide the complete project and environment information if it will help.
My current workaround is replacing lambda with an anonymous function:
@Composable
private fun RandomActivityButton() {
lateinit var onClickNormal: () -> Unit
lateinit var onClick: State<() -> Unit>
onClickNormal = {
val intent = Intent(
this@MainActivity,
ActivityDescriptionActivity::class.java
)
val activity = mainScope.async(Dispatchers.IO) {
//BoredApi().randomAsync().await()
BoredApi().byCriterionsAsync(fun BoredApi.CriterionSelection.() {
Key set 6509779
}).await()
}
onClick.value = {}
mainScope.launch {
intent.putExtra("activity", activity.await())
startActivity(intent)
onClick.value = onClickNormal
}
}
onClick = +state { onClickNormal }
Button(
text = "navigate",
onClick = onClick.value
)
}