Open mbertschler opened 2 months ago
Hey @mbertschler, thanks!
I understand this problem. This is actually a Golang related one:
https://go.dev/play/p/nYw6xmQ9Ll2
package main
import (
"fmt"
"reflect"
)
type MyInt int
func main() {
var my MyInt = 1
var i int = 1
fmt.Println(my == i) // Compilation will fail.
fmt.Println(reflect.DeepEqual(my, i)) // Will return false.
}
Recently in #611 we improved int()
builtin function to unwrap custom int types:
int(Named) == 4 // This will work in Expr.
One thing you can do is to write a patcher which will wrap all custom ints with int(...)
call.
Hey @antonmedv. Thanks for this amazing library, it is a lot of fun to work with.
After deciding to use it for a new feature with dynamic configuration, we unfortunately ran into some unexpected behavior. The problem is that the expression
Named == 4
returnsfalse
with this environment definition:It seems to be because we use a named type
NamedUint
instead of the basic typeuint32
in our struct.Is this behavior expected?
Reproducing Test
Version:
github.com/expr-lang/expr v1.16.1