Created
November 3, 2025 22:22
-
-
Save swankjesse/579bc0976fcdc561d4c7db6bcc271301 to your computer and use it in GitHub Desktop.
Demonstrates a bug in the Kotlin 2.2.21 compiler
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import assertk.assertThat | |
| import assertk.assertions.isEqualTo | |
| import kotlin.test.Test | |
| import kotlinx.coroutines.coroutineScope | |
| import kotlinx.coroutines.launch | |
| import kotlinx.coroutines.runBlocking | |
| class SuspendReturnTest { | |
| @Test | |
| fun directlyCallImplicitReturn() = runBlocking { | |
| assertThat(ImplicitReturn().invoke()).isEqualTo(Unit) | |
| } | |
| @Test | |
| fun directlyCallExplicitReturn() = runBlocking { | |
| assertThat(ExplicitReturn().invoke()).isEqualTo(Unit) | |
| } | |
| @Test | |
| fun indirectlyCallImplicitReturn() = runBlocking { | |
| assertThat(CallImplicitReturn().call()).isEqualTo(Unit) | |
| } | |
| @Test | |
| fun indirectlyCallExplicitReturn() = runBlocking { | |
| assertThat(CallExplicitReturn().call()).isEqualTo(Unit) | |
| } | |
| class CallImplicitReturn { | |
| suspend fun call(): Any? { | |
| return ImplicitReturn().invoke() | |
| } | |
| } | |
| class ImplicitReturn { | |
| suspend fun invoke() { | |
| // Note that this doesn't have a 'return' operator. | |
| coroutineScope { | |
| launch { | |
| } | |
| } | |
| } | |
| } | |
| class CallExplicitReturn { | |
| suspend fun call(): Any? { | |
| return ExplicitReturn().invoke() | |
| } | |
| } | |
| class ExplicitReturn { | |
| suspend fun invoke() { | |
| // Note that this has a 'return' operator. | |
| return coroutineScope { | |
| launch { | |
| } | |
| } | |
| } | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment