Skip to content

Commit

Permalink
Add a test case
Browse files Browse the repository at this point in the history
  • Loading branch information
chriso committed Nov 8, 2023
1 parent 2f8a3d2 commit 4d48581
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions compiler/coroutine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions compiler/testdata/coroutine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit 4d48581

Please sign in to comment.