Accepting value with _ does not work,Just like this : map["a"], _ = get()
dairui520 opened this issue · 0 comments
dairui520 commented
The following program sample.go
triggers an unexpected result
const src1 = `
package main
import (
"context"
"fmt"
"reflect"
"errors"
)
func Process(ctx context.Context, input map[string]interface{}) ( map[string]interface{}, error) {
attr := make(map[string]string)
attr["pk_forum"] = input["pkForumStr"].(string)
output := make(map[string]interface{})
output["a"], _ = get()
fmt.Println(output)
return output, nil
}
func get() (string, error) {
return "", errors.New("test error")
}
`
func main() {
m := make(map[string]interface{})
m["pkForumStr"] = ""
i := interp.New(interp.Options{GoPath: build.Default.GOPATH})
err := i.Use(stdlib.Symbols)
if err != nil {
fmt.Println(err)
}
_, err = i.Eval(src1)
if err != nil {
panic(err)
}
v, err := i.Eval("main.Process")
if err != nil {
panic(err)
}
bar := v.Interface().(func(context.Context, map[string]interface{}) (map[string]interface{}, error))
r, err := bar(context.Background(), m)
if err != nil {
fmt.Println(err)
}
fmt.Println(r)
}
Expected result
map[a:getTest]
Got
map[]
Yaegi Version
v0.15.1
Additional Notes
I have tried several methods and found that when accepting values through map, it is ineffective. I think this is a bug and look forward to its fix.
Go 1.20