-
-
Notifications
You must be signed in to change notification settings - Fork 528
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
Make new destination slice when length doesn't match. #84
Conversation
👍 just ran into this too, thank you @mrdg Any chance we can merge this in @BurntSushi ? |
Yes please! This is very useful if you want to unmarshal into a slice type that you've populated with default values. encoding/json lets you do this. |
This bit me today. Please merge this fix (or fix it otherwise). |
I want to use this. Would you merge it? |
@@ -308,7 +308,7 @@ func (md *MetaData) unifySlice(data interface{}, rv reflect.Value) error { | |||
return badtype("slice", data) | |||
} | |||
sliceLen := datav.Len() | |||
if rv.IsNil() { | |||
if rv.IsNil() || rv.Len() != datav.Len() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead you might want to only do this if rv.Cap() < datav.Len()
and otherwise rv.SetLen(datav.Len())
. But it's an optimization that probably doesn't matter for most TOML use cases.
@BurntSushi bump. This fix is ready to go. |
please release! |
Merged, thanks! I made the change I mentioned in 0c4ce10. |
The bug was fixed by BurntSushi/toml#84. Also adding gdm install to `make tools`.
thanks!! |
Fixes #83