diff --git a/lib/std/core/hnd.kk b/lib/std/core/hnd.kk index cf75f406e..8038a8c5f 100644 --- a/lib/std/core/hnd.kk +++ b/lib/std/core/hnd.kk @@ -546,9 +546,16 @@ pub fun resume-shallow( r : resume-context, x : b ) : e0 r cast-ev1(r.k)(Shallow(x)) -pub fun finalize( r : resume-context, x : r ) : e r - //finalize(r.k,x) - (r.k)(Finalize(x)) +// Applying the continuation with an immediate throw restores the handler which expects a return type `r` +// But because we are manually finalizing out of context, we are returning in a new context +// where only `()` makes sense, because we do not want to require a dummy value to finalize +extern unsafe-cast-unit-context(r: resume-context): resume-context + c inline "#1" + js inline "#1" + +pub fun finalize( r : resume-context ) : e () + // finalize(r.k,x) + (unsafe-cast-unit-context(r).k)(Finalize(())) // ------------------------------------------- // Clauses