Fixed incorrect assignable types order in invocation

This commit is contained in:
Leon Mika 2024-03-10 00:09:33 +00:00
parent e7cb026708
commit dbce4f6dce
2 changed files with 19 additions and 1 deletions

View file

@ -1,6 +1,7 @@
package events package events
import ( import (
"context"
"errors" "errors"
"fmt" "fmt"
"testing" "testing"
@ -34,6 +35,23 @@ func TestNew_Lifecycle(t *testing.T) {
}, receives) }, receives)
} }
func TestFire(t *testing.T) {
t.Run("should preserve context.Context", func(t *testing.T) {
var wasFired bool
d := New()
d.On("event", func(ctx context.Context) {
assert.NotNil(t, ctx)
wasFired = true
})
d.Fire("event", context.Background())
assert.True(t, wasFired)
})
}
func TestTryFire(t *testing.T) { func TestTryFire(t *testing.T) {
errVal := errors.New("bang") errVal := errors.New("bang")

View file

@ -27,7 +27,7 @@ func (rh *receiptHandler) invoke(values preparedArgs) error {
for i := range args { for i := range args {
args[i] = reflect.Zero(rh.funcType.In(i)) args[i] = reflect.Zero(rh.funcType.In(i))
if i < len(values) { if i < len(values) {
if rh.funcType.In(i).AssignableTo(values[i].Type()) { if values[i].Type().AssignableTo(rh.funcType.In(i)) {
args[i] = values[i] args[i] = values[i]
} }
} }