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

Make new destination slice when length doesn't match. #84

Merged
merged 1 commit into from
Feb 23, 2016

Conversation

mrdg
Copy link
Contributor

@mrdg mrdg commented Jun 5, 2015

Fixes #83

@jszwedko
Copy link

👍 just ran into this too, thank you @mrdg

Any chance we can merge this in @BurntSushi ?

@cespare
Copy link
Collaborator

cespare commented Jul 27, 2015

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.

@chowey
Copy link

chowey commented Sep 9, 2015

This bit me today. Please merge this fix (or fix it otherwise).

@kteru
Copy link

kteru commented Oct 8, 2015

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() {
Copy link
Collaborator

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.

@cespare
Copy link
Collaborator

cespare commented Jan 8, 2016

@BurntSushi bump. This fix is ready to go.

@pyama86
Copy link

pyama86 commented Feb 20, 2016

please release!

@cespare cespare merged commit 110f954 into BurntSushi:master Feb 23, 2016
@cespare
Copy link
Collaborator

cespare commented Feb 23, 2016

Merged, thanks!

I made the change I mentioned in 0c4ce10.

@pyama86
Copy link

pyama86 commented Feb 23, 2016

thanks!!

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

Successfully merging this pull request may close these issues.

6 participants