-
-
Notifications
You must be signed in to change notification settings - Fork 475
Open
Description
ValueGetter is not supported inmap:
https://go.dev/play/p/cutaKAgIxHj
package main
import (
"fmt"
"github.com/expr-lang/expr"
"github.com/expr-lang/expr/patcher/value"
"github.com/expr-lang/expr/vm"
)
type customInt struct {
Int int
}
func (v *customInt) AsInt() int {
return v.Int
}
func (v *customInt) AsAny() any {
return v.Int
}
func main() {
env := map[string]any{
"params": map[string]any{
"ValueOne": &customInt{1},
"ValueTwo": &customInt{2},
},
}
program, err := expr.Compile(
"params.ValueOne + params.ValueTwo",
expr.Env(env),
value.ValueGetter,
)
if err != nil {
fmt.Println(err)
return
}
out, err := vm.Run(program, env)
if err != nil {
panic(err)
}
fmt.Println(out)
}The code above produced the following error:
panic: invalid operation: main.customInt + main.customInt (1:17)
| params.ValueOne + params.ValueTwo
| ................^
goroutine 1 [running]:
main.main()
/tmp/sandbox3933238168/prog.go:43 +0x249
Program exited.
In my scenario, it's not possible to define a specific struct. Is there any way to solve this problem?
Metadata
Metadata
Assignees
Labels
No labels