Skip to content

Bug: inconsistencies with variadic function arguments #817

Description

@diegommm

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.

Go Playground

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

Go Playground

The following code:

fmt.Println(expr.Eval(
`thing(nil)`,
map[string]any{
"thing": func(arg...any) string {
returnfmt.Sprintf("result: (%T) %v", arg[0], arg[0])
},
},
))

Produces the output:

result: ([]interface {}) [] <nil>

Expected output:

result: (<nil>) <nil> <nil>

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions