expr: `integer divide by zero` detection broken on master branch
I just updated the expr to latest commit on @master and one of the my unit test is failed. Here is a simple, reproducible code snippet:
package main
import (
"fmt"
"github.com/antonmedv/expr"
)
func main() {
env := map[string]uint64{
"foo": 7,
"bar": 0,
}
code := `(foo / bar) < 10`
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.Println(output)
}
I was expecting the following error:
panic: runtime error: integer divide by zero (1:6)
| (foo / bar) < 10
| .....^
Works as expected: v1.9.0
Broken (tested at): v1.9.1-0.20221106120435-3d4c21954310
If bar is 0 in the following expression: (foo / bar) < 10, should be resulting an error.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 33 (15 by maintainers)
Yeap, it is possible via
expr.Function. But right now there is a bug #408Your first example is incorrect. It will not work. Visitor with Patch is the correct way.
@Dentrax
1 / (1 - 1)is1/0is+Inf. So no error should be here.On the other hand
1 % 0is an error still.@roqenrox I’m also thinking to add
1 < 2 < 3chained comparison. Same as in Julia.This is how int behaves. Not a mistake from the programmer’s perspective. But kinda a mistake from user’s perspective.