From 909c9060809303ddb4533cf841f51e7b8694e266 Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Tue, 23 May 2023 20:08:57 -0500 Subject: [PATCH] Fix yields inside nested fibers. --- src/core/vm.c | 1 + test/suite0001.janet | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/src/core/vm.c b/src/core/vm.c index 3a29e207..b7e67df1 100644 --- a/src/core/vm.c +++ b/src/core/vm.c @@ -1423,6 +1423,7 @@ static JanetSignal janet_continue_no_check(JanetFiber *fiber, Janet in, Janet *o if (sig != JANET_SIGNAL_OK && !(child->flags & (1 << sig))) { *out = in; janet_fiber_set_status(fiber, sig); + fiber->last_value = child->last_value; return sig; } /* Check if we need any special handling for certain opcodes */ diff --git a/test/suite0001.janet b/test/suite0001.janet index ccda77e4..3d156d32 100644 --- a/test/suite0001.janet +++ b/test/suite0001.janet @@ -360,4 +360,11 @@ (assert (= (or 1) 1) "or 1") (assert (= (or) nil) "or with no arguments") +(def yielder + (coro + (defer (yield :end) + (repeat 5 (yield :item))))) +(def items (seq [x :in yielder] x)) +(assert (deep= @[:item :item :item :item :item :end] items) "yield within nested fibers") + (end-suite)