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

Decode S=[] into a non-nil []interface{}. #339

Merged
merged 1 commit into from Jan 12, 2022

Conversation

dtcaciuc
Copy link
Contributor

This restores v0.3 behaviour and also makes it
consistent with how the same decodes into something
like struct { S []string }.

Closes #338

This restores v0.3 behaviour and also makes it
consistent with how the same decodes into something
like struct { S []string }.

Closes BurntSushi#338
@dtcaciuc
Copy link
Contributor Author

The struct behaviour I'm referring to is already tested in TestDecodeSlices

@@ -618,6 +618,17 @@ func TestDecodeSlices(t *testing.T) {
}
}

func TestDecodeInterfaceSlice(t *testing.T) {
var v map[string]interface{}
if _, err := Decode(`S = []`, &v); err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you also test nested arrays and inline tables?

arr = []
nested = [[]]
tbl = {arr = []}

Just to make sure this keeps working in all future updates!

Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually, looking at this a bit closer the tests should be integrated with TestDecodeSlices, I'll just merge this as-is and fix it up; thanks!

// Initialize to a non-nil empty slice. This makes it
// consistent with how S = [] decodes into a non-nil slice
// inside something like struct { S []string }.
array = []interface{}{}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you mention your issue in this comment? Just for future reference.

Also, might as well move this up with the declaration: array = []interface{}{} rather than defining it and then assigning a value.

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.

x = [] decodes into nil
2 participants