Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

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.

@mitchellh mitchellh merged commit fb53316 into mitchellh:master Jul 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
2 participants