From 4d485818c1fa6ab6c289fc8dc90198305ee832eb Mon Sep 17 00:00:00 2001 From: Chris O'Hara Date: Wed, 8 Nov 2023 14:55:43 +1000 Subject: [PATCH] Add a test case --- compiler/coroutine_test.go | 6 ++++++ compiler/testdata/coroutine.go | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/compiler/coroutine_test.go b/compiler/coroutine_test.go index 6c0728e..39a9710 100644 --- a/compiler/coroutine_test.go +++ b/compiler/coroutine_test.go @@ -198,6 +198,12 @@ func TestCoroutineYield(t *testing.T) { coro: func() { VarArgs(3) }, yields: []int{0, 1, 2}, }, + + { + name: "closure yield", + coro: func() { YieldFromClosure(3) }, + yields: []int{3}, + }, } // This emulates the installation of function type information by the diff --git a/compiler/testdata/coroutine.go b/compiler/testdata/coroutine.go index 3f65478..35ced98 100644 --- a/compiler/testdata/coroutine.go +++ b/compiler/testdata/coroutine.go @@ -547,3 +547,13 @@ func varArgs(args ...int) { coroutine.Yield[int, any](arg) } } + +func YieldFromClosure(n int) { + closure(n)() +} + +func closure(arg int) func() { + return func() { + coroutine.Yield[int, any](arg) + } +}