-
-
Notifications
You must be signed in to change notification settings - Fork 452
Open
Labels
Description
Issue 1: nil
as last variadic arg panics
This only happens when the number of arguments is greater than one. If nil
is passed as the single variadic arg then the Issue 2 is observed.
The following code:
fmt.Println(expr.Eval(
`sprintf("result: %v %v", 1, nil)`,
map[string]any{
"sprintf": fmt.Sprintf,
},
))
Produces the output:
<nil> runtime error: index out of range [2] with length 2 (1:1)
| sprintf("result: %v %v", 1, nil)
| ^
Expected output:
result: 1 nil <nil>
Issue 2: single nil
variadic arg interpreted as empty []any
The following code:
fmt.Println(expr.Eval(
`thing(nil)`,
map[string]any{
"thing": func(arg ...any) string {
return fmt.Sprintf("result: (%T) %v", arg[0], arg[0])
},
},
))
Produces the output:
result: ([]interface {}) [] <nil>
Expected output:
result: (<nil>) <nil> <nil>