Open
Description
When using the expr.WithContext
option, the named variable must also be provided at compilation time using expr.Env
, otherwise the patch seems to fail to correctly update calls to functions that require a context. (I'm not exactly sure why this happens, but if it's necessary, perhaps we should document it?)
Reproduction:
env := map[string]any{
`cancelled`: func(ctx context.Context) bool {
return ctx.Err() != nil
},
`ctx`: context.Background(),
}
program, err := expr.Compile(`cancelled()`,
expr.WithContext(`ctx`),
// expr.Env(env),
)
if err != nil {
panic(err)
}
output, err := expr.Run(program, env)
if err != nil {
panic(err)
}
fmt.Println(output)
With the expr.Env
line commented out, this will fail (see playground), and with it uncommented, it succeeds (see playground). The error produced at runtime is:
reflect: Call with too few input arguments (1:1)
| cancelled()
| ^
Metadata
Assignees
Labels
No labels
Activity