Skip to content

Commit

Permalink
Add another basic test
Browse files Browse the repository at this point in the history
  • Loading branch information
chriso committed Dec 12, 2023
1 parent 262d4ec commit 46c3191
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
12 changes: 12 additions & 0 deletions compiler/coroutine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions compiler/testdata/coroutine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
15 changes: 15 additions & 0 deletions compiler/testdata/coroutine_durable.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 46c3191

Please sign in to comment.