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

Ensure that intermediate maps during struct to struct decoding are settable #203

Merged
merged 1 commit into from Jul 22, 2020

Conversation

mkeeler
Copy link
Contributor

@mkeeler mkeeler commented Jul 22, 2020

Fixes #202

Copy link
Owner

@mitchellh mitchellh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. I'm gonna merge as-is despite my comment. Its not a big deal. But note!

// indirection allows the underlying map to be settable (CanSet() == true)
// where as reflect.MakeMap returns an unsettable map.
addrVal := reflect.New(vMap.Type())
reflect.Indirect(addrVal).Set(vMap)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you know its a pointer I usually prefer addrVal.Elem() over indirect. Indirect just calls that with an additional check but it feels more idiomatic reflect usage. Same with the few other uses.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants