Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accepting value with _ does not work,Just like this : map["a"], _ = get() #1655

Open
dairui520 opened this issue Aug 8, 2024 · 0 comments

Comments

@dairui520
Copy link

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

@dairui520 dairui520 changed the title 用_ 接受值,不起作用 Accepting value with _ does not work, Aug 8, 2024
@dairui520 dairui520 changed the title Accepting value with _ does not work, Accepting value with _ does not work,Just like this : map["a"], _ = get() Aug 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant