Skip to main content
Journey Uncommon Logo
JourneyUncommon
hardKotlinCOROUTINE_SUSPENDED sentinelSingle-choice MCQ

Consider how the compiler narrows the return type at a suspension point. A suspend function calls g() whose lowered JVM return type is Any?. The bytecode does: val r = g(this); if (r === COROUTINE_SUSPENDED) return COROUTINE_SUSPENDED. After that guard, how does the generated code obtain a properly typed value to keep working with?

val r: Any? = g(this) if (r === COROUTINE_SUSPENDED) return COROUTINE_SUSPENDED // what happens to r here?