From 46c3191a6ab890eb7a2961ac4b4a762b124357ed Mon Sep 17 00:00:00 2001 From: Chris O'Hara Date: Tue, 12 Dec 2023 12:42:55 +1000 Subject: [PATCH] Add another basic test --- compiler/coroutine_test.go | 12 ++++++++++++ compiler/testdata/coroutine.go | 16 ++++++++++++++++ compiler/testdata/coroutine_durable.go | 15 +++++++++++++++ 3 files changed, 43 insertions(+) diff --git a/compiler/coroutine_test.go b/compiler/coroutine_test.go index 7835ced..d6e92c8 100644 --- a/compiler/coroutine_test.go +++ b/compiler/coroutine_test.go @@ -220,6 +220,18 @@ func TestCoroutineYield(t *testing.T) { coro: func() { IdentityGeneric[int](11) }, yields: []int{11}, }, + + { + name: "identity generic (2)", + coro: func() { IdentityGenericInt(11) }, + yields: []int{11}, + }, + + { + name: "identity generic (3)", + coro: func() { IdentityGenericStructInt(11) }, + yields: []int{11}, + }, } // This emulates the installation of function type information by the diff --git a/compiler/testdata/coroutine.go b/compiler/testdata/coroutine.go index 3678de2..92d7218 100644 --- a/compiler/testdata/coroutine.go +++ b/compiler/testdata/coroutine.go @@ -561,3 +561,19 @@ func ReturnNamedValue() (out int) { func IdentityGeneric[T any](n T) { coroutine.Yield[T, any](n) } + +type IdentityGenericStruct[T any] struct { + n T +} + +func (i *IdentityGenericStruct[T]) Run() { + coroutine.Yield[T, any](i.n) +} + +func IdentityGenericInt(n int) { + IdentityGeneric[int](n) +} + +func IdentityGenericStructInt(n int) { + (&IdentityGenericStruct[int]{n: n}).Run() +} diff --git a/compiler/testdata/coroutine_durable.go b/compiler/testdata/coroutine_durable.go index d9b71d3..f13ce47 100644 --- a/compiler/testdata/coroutine_durable.go +++ b/compiler/testdata/coroutine_durable.go @@ -3239,12 +3239,27 @@ func ReturnNamedValue() (_fn0 int) { //go:noinline func IdentityGeneric[T any](n T) { coroutine.Yield[T, any](n) } + +type IdentityGenericStruct[T any] struct { + n T +} + +//go:noinline +func (i *IdentityGenericStruct[T]) Run() { coroutine.Yield[T, any](i.n) } + +//go:noinline +func IdentityGenericInt(n int) { IdentityGeneric[int](n) } + +//go:noinline +func IdentityGenericStructInt(n int) { (&IdentityGenericStruct[int]{n: n}).Run() } func init() { _types.RegisterFunc[func(n int)]("github.com/stealthrocket/coroutine/compiler/testdata.Double") _types.RegisterFunc[func(_fn0 int)]("github.com/stealthrocket/coroutine/compiler/testdata.EvenSquareGenerator") _types.RegisterFunc[func(_fn0 int)]("github.com/stealthrocket/coroutine/compiler/testdata.FizzBuzzIfGenerator") _types.RegisterFunc[func(_fn0 int)]("github.com/stealthrocket/coroutine/compiler/testdata.FizzBuzzSwitchGenerator") _types.RegisterFunc[func(n int)]("github.com/stealthrocket/coroutine/compiler/testdata.Identity") + _types.RegisterFunc[func(n int)]("github.com/stealthrocket/coroutine/compiler/testdata.IdentityGenericInt") + _types.RegisterFunc[func(n int)]("github.com/stealthrocket/coroutine/compiler/testdata.IdentityGenericStructInt") _types.RegisterFunc[func(_ int)]("github.com/stealthrocket/coroutine/compiler/testdata.LoopBreakAndContinue") _types.RegisterFunc[func(_fn1 int)]("github.com/stealthrocket/coroutine/compiler/testdata.MethodGenerator") _types.RegisterFunc[func(_fn0 int) (_ int)]("github.com/stealthrocket/coroutine/compiler/testdata.NestedLoops")