Rohen Giralt
06/07/2026, 3:00 PMfun foo(): Int {
while (true) {
return 0
}
}
But this doesn't (it gives "Return type mismatch: expected 'Int', actual 'Unit"):
fun foo(): Int = run {
while (true) {
return@run 0
}
}
This compiles, but warns that the second 0 is unreachable code.
fun foo(): Int = run {
while (true) {
return@run 0
}
0
}
Does anyone know why? And is there any way to write code like the second example without any warnings? (In my case, this is occurring with coroutineScope, so I can't just remove it like one could with run).Youssef Shoaib [MOD]
06/07/2026, 3:36 PMfun foo(): Int = run {
forever {
return@run 0
}
}
inline fun forever(block: () -> Unit): Nothing {
while (true) block()
}Rohen Giralt
06/07/2026, 3:37 PMYoussef Shoaib [MOD]
06/07/2026, 5:25 PM