govaluate
govaluate copied to clipboard
error when passing []interface{} to function or method
Using function like this:
udfs := map[string]govaluate.ExpressionFunction{
"f": func(args ...interface{}) (interface{}, error) {
arg := args[0].([]interface{})
return arg[0], nil
},
}
exp, _ := govaluate.NewEvaluableExpressionWithFunctions("f(p)", udfs)
params := map[string]interface{}{}
params["p"] = []interface{}{"ab", "cd", "e"} // []interface{}{[]interface{}{"ab", "cd", "e"}} is ok
res, err := exp.Evaluate(params)
panic: interface conversion: interface {} is string, not []interface {}
This happens because the parser doesn't differentiate between arrays passed as parameters, and an array made with separators (such as (1, 2, 3)). They both end up as []interface{}, and the function call treats them both as "expanded" (i.e., passes to the ExpressionFunction as foo...).
Going to call this a bug, I doubt anyone expects this behavior.
Hi, is there any progress on this bug?
any update here?