-
-
Notifications
You must be signed in to change notification settings - Fork 434
Error in v1.10.1: interface {} is func(interface {}) float64, not func(string) float64 #310
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I see. Will try to fix this bug. |
@antonmedv awesome glad it is a bug, and thank you for the great library :D |
@zachaller will try to fix it over the weekend. |
I need little bit more info, as this code works as expected: package main
import (
"fmt"
"reflect"
"strconv"
"github.com/antonmedv/expr"
)
func main() {
env := map[string]interface{}{
"int8": int8(1),
"asFloat": asFloat,
}
code := `asFloat(int8)`
program, err := expr.Compile(code, expr.Env(env))
if err != nil {
panic(err)
}
output, err := expr.Run(program, env)
if err != nil {
panic(err)
}
fmt.Printf("%T(%v)", output, output)
}
func asFloat(in interface{}) float64 {
switch i := in.(type) {
case float64:
return i
case float32:
return float64(i)
case int64:
return float64(i)
case int32:
return float64(i)
case int16:
return float64(i)
case int8:
return float64(i)
case int:
return float64(i)
case uint64:
return float64(i)
case uint32:
return float64(i)
case uint16:
return float64(i)
case uint8:
return float64(i)
case uint:
return float64(i)
case string:
inAsFloat, err := strconv.ParseFloat(i, 64)
if err == nil {
return inAsFloat
}
panic(err)
}
panic(fmt.Sprintf("asFloat() not supported on %v %v", reflect.TypeOf(in), in))
} Can you create an example with error? Thanks. |
The error occurs when converting a string to float using |
Ok, thanks. This is a regression test: func TestFastCall(t *testing.T) {
env := map[string]interface{}{
"func": func(in interface{}) float64 {
return 8
},
}
code := `func("8")`
program, err := expr.Compile(code, expr.Env(env))
assert.NoError(t, err)
out, err := expr.Run(program, env)
assert.NoError(t, err)
assert.Equal(t, float64(8), out)
} |
Fixed in 9009d4d Will release a new version. |
Awesome thank you for the super quick turnaround! |
I have another one:
However, I have: type classifyStringFunc func(string) bool I can work around the issue with type classifyStringFunc = func(string) bool Maybe do you prefer another issue? |
Yes, please. |
We use this in argo-rollouts code base and when we dependabot upgraded use to 1.10 we now have our unit tests failing with this error
I have done a little bit of digging and it seems like this file got added which defines a set of functions. This seems to break our env which we have defined here I think because it is missing the type of functions we have passed in such as asFloat
The text was updated successfully, but these errors were encountered: