-
-
Notifications
You must be signed in to change notification settings - Fork 464
Closed
Description
Good day everyone!
I might be wrong, but it seems to me that method precedence over keyed value is not documented anywhere. And I'm not even sure if this behavior is stable. Because of this, I don't think foo.bar should be equivalent to foo[bar].
package main
import (
"fmt"
"github.com/expr-lang/expr"
)
type mapWithMethod map[string]func() string
func (m mapWithMethod) GetString() string {
return "thise is from method"
}
func GetString() string {
return "thise is from func"
}
type env struct {
M mapWithMethod
}
func main() {
env := env{
M: mapWithMethod{"GetString": GetString},
}
prog, _ := expr.Compile(`M.GetString()`, expr.Env(env), expr.Optimize(true))
result, _ := expr.Run(prog, env)
fmt.Println(result)
//Output: thise is from method
}
Metadata
Metadata
Assignees
Labels
No labels