Ok. I finally got to a computer to check that. There is a bug, but it is not what I’ve originally though it is:
https://youtrack.jetbrains.com/issue/KT-18486
In short, when you uncomment the invocation of suspendDummy()
it tricks the compiler into generating non-efficient code for runSuspendsion
. Semantically it is correct, though. interceptContinuation
should be called, by design, for each instance of state machine, so if you have multiple state-machines (multiple complex function) running as a part of the same coroutine, the you’ll see interceptContinuation
invoked multiple times (once of each state-machine instance). It is just in this case a function runSuspension
that should have been treated by compiler as a simple tail-only suspending function, is mistakenly treated as a complex suspending function with a state machine.
UPDATE: Good news is that this bug is already fixed in the Kotlin master (it will be fixed in version 1.1.4)