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

panic: reflect.Value.Convert: value of type unsafe.Pointer cannot be converted to #33610

freboat opened this issue Aug 12, 2019 · 2 comments


Copy link

commented Aug 12, 2019

What version of Go are you using (go version)?

$ go version

Does this issue reproduce with the latest release?

What operating system and processor architecture are you using (go env)?

go env Output
$ go env

What did you do?

//make a complict map for a point is easy
func mkmapStatic(ptr *map[string]int) {
    *ptr = make(map[string]int)
    (*ptr)["abc"] = 5
    (*ptr)["ced"] = 6
    fmt.Println("ptr: ", len(*ptr))

//but how to make a dynamic map by reflect
//in: a in map intf,need to copy
//out: a map ponter to out obj
func mkmapDynamic(in interface{}, out unsafe.Pointer ) {
     vin := reflect.ValueOf(in)
     tin := reflect.TypeOf(in)
     vout := reflect.ValueOf(out)
     //here panic: reflect.Value.Convert: value of type unsafe.Pointer cannot be converted to type map[string]int
     //how to copy in data to out ?
     mptr := vout.Convert(reflect.PtrTo(tin)) 

func testmap() {
    var mpin, mpout map[string]int
    mkmapDynamic(mpin, unsafe.Pointer(&mpout))

What did you expect to see?

make a map by reflect.TypeOf, and set it into a unsafe.Pointer

What did you see instead?

panic: reflect.Value.Convert: value of type unsafe.Pointer


This comment has been minimized.

Copy link

commented Aug 13, 2019

I see you've written some comments in the code, but can you please copy them to fill in the answers to the "What did you expect to see?" and "What did you see instead?" questions. That'll make it easier to understand where the problem is. Thanks.


This comment has been minimized.

Copy link

commented Aug 17, 2019

My understanding is that this is intentional. If the reflect package permitted this conversion it would permit unsafe pointer conversions in packages that do not import the "unsafe" package. Closing the issue, but please comment if you disagree.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
3 participants
You can’t perform that action at this time.