@@ -683,7 +683,7 @@ internal open class BufferedChannel<E>(
683683 // If `receive()` decides to suspend, the corresponding
684684 // `suspend` function that creates a continuation is called.
685685 // The tail-call optimization is applied here.
686- onNoWaiterSuspend = { segm, i, r -> unwrapTyped( receiveOnNoWaiterSuspend(segm, i, r) ) }
686+ onNoWaiterSuspend = { segm, i, r -> receiveOnNoWaiterSuspend(segm, i, r) }
687687 )
688688
689689 private suspend fun receiveOnNoWaiterSuspend (
@@ -706,8 +706,9 @@ internal open class BufferedChannel<E>(
706706 // not dispatched yet. In case `onUndeliveredElement` is
707707 // specified, we need to invoke it in the latter case.
708708 onElementRetrieved = { element ->
709- val onCancellation = onUndeliveredElement?.bindCancellationFun(unwrapTyped(element), cont.context)
710- cont.resume(element, onCancellation)
709+ val unwrapped: E = unwrapTyped(element)
710+ val onCancellation = onUndeliveredElement?.bindCancellationFun(unwrapped, cont.context)
711+ cont.resume(unwrapped, onCancellation)
711712 },
712713 onClosed = { onClosedReceiveOnNoWaiterSuspend(cont) },
713714 )
@@ -737,7 +738,7 @@ internal open class BufferedChannel<E>(
737738 },
738739 onSuspend = { _, _, _ -> error(" unexpected" ) },
739740 onClosed = { closed(closeCause) },
740- onNoWaiterSuspend = { segm, i, r -> unwrapTyped( receiveCatchingOnNoWaiterSuspend(segm, i, r) ) }
741+ onNoWaiterSuspend = { segm, i, r -> receiveCatchingOnNoWaiterSuspend(segm, i, r) }
741742 )
742743
743744 private suspend fun receiveCatchingOnNoWaiterSuspend (
0 commit comments