-
-
Notifications
You must be signed in to change notification settings - Fork 473
Closed
Labels
Description
When calling a function that receives a single float (any other type seems to work properly), expr.Compile now allows the argument to be of any type.
These tests reflect the issue:
func TestIssue(t *testing.T) {
t.Parallel()
testCases := []struct {
name string
code string
fail bool
}{
{
name: `when the parameter is a string`,
code: `func("invalid")`,
fail: true,
},
{
name: `when the parameter is a bool`,
code: `func(true)`,
fail: true,
},
{
name: `when the parameter is an array`,
code: `func([])`,
fail: true,
},
{
name: `when the parameter is a map`,
code: `func({})`,
fail: true,
},
{
name: `when the parameter is an integer`,
code: `func(1)`,
fail: false,
},
{
name: `when the parameter is a float`,
code: `func(1.5)`,
fail: false,
},
}
for _, tc := range testCases {
ltc := tc
t.Run(ltc.name, func(t *testing.T) {
t.Parallel()
function := expr.Function("func", func(params ...any) (any, error) {
return true, nil
}, new(func(float64) bool))
_, err := expr.Compile(ltc.code, function)
if ltc.fail {
if err == nil {
t.Error("expected an error, but it was nil")
t.FailNow()
}
} else {
if err != nil {
t.Errorf("expected nil, but it was %v", err)
t.FailNow()
}
}
})
}
}The behavior was changed in v1.15.0 and still persists in v1.15.4.