Open
Description
The following program incorrectly assumes that the type of $env
is map[string]any
, although args[0]
holds Env
:
package main
import (
"fmt"
"time"
"github.com/davecgh/go-spew/spew"
"github.com/expr-lang/expr"
)
type Env struct {
}
func (Env) Dump(args ...any) (any, error) {
spew.Dump(args)
return nil, nil
}
func main() {
code := `dump($env)`
env := Env{}
program, err := expr.Compile(code,
expr.Function("dump", env.Dump, new(func(Env) any)),
//expr.Function("dump", env.Dump, new(func(any) any)),
expr.Env(env)) // Pass the struct as an environment.
if err != nil {
panic(err)
}
output, err := expr.Run(program, env)
if err != nil {
panic(err)
}
fmt.Print(output)
}
Changing expr.Function("dump", env.Dump, new(func(Env) any))
to expr.Function("dump", env.Dump, new(func(any) any))
will allow to compile the program and inspect the type of the arg.