diff --git a/functions.go b/functions.go index ff5e76e..a3460c9 100644 --- a/functions.go +++ b/functions.go @@ -114,7 +114,9 @@ func createCallArguments(ctx context.Context, t reflect.Type, args []interface{} inType = t.In(numIn - 1).Elem() } argVal := reflect.ValueOf(arg) - if arg == nil || !argVal.Type().AssignableTo(inType) { + if arg == nil { + argVal = reflect.ValueOf(reflect.Interface) + } else if !argVal.Type().AssignableTo(inType) { return nil, fmt.Errorf("expected type %s for parameter %d but got %T", inType.String(), i, arg) } diff --git a/functions_test.go b/functions_test.go index 7bcf07c..c12b1a7 100644 --- a/functions_test.go +++ b/functions_test.go @@ -130,6 +130,17 @@ func Test_toFunc(t *testing.T) { }, wantErr: context.DeadlineExceeded, }, + { + name: "nil arg", + function: func(a interface{}) bool { + if a != nil { + return true + } + return false + }, + arguments: []interface{}{nil}, + want: true, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {