-
Notifications
You must be signed in to change notification settings - Fork 307
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
cue: decode empty list as empty slice instead of slice-typed nil #2471
Conversation
Signed-off-by: Artem V. Navrotskiy <[email protected]>
Is there a github issue that this PR is fixing? I would suggest filing an issue first if not, because this is a subtle change in behavior that we need to agree is a good idea first. |
I don't find related github issue, but at least two of my colleagues mentioned this problem before I encountered it.
I will be very surprised if the test case (current behaviour): {
value: `[]`,
dst: new(interface{}),
want: ([]interface{})(nil),
}, {
value: `[]`,
dst: new([]interface{}),
want: []interface{}{},
}, {
value: `[]`,
dst: new([]int),
want: []int{},
} will be more preferable than (new behaviour): {
value: `[]`,
dst: new(interface{}),
want: []interface{}{},
}, {
value: `[]`,
dst: new([]interface{}),
want: []interface{}{},
}, {
value: `[]`,
dst: new([]int),
want: []int{},
} |
That is, now an empty list turns into a slice-typed |
I see. I think I agree with that, for the sake of consistency. Most other decoders in Go, like encoding/json, also do that:
I'll check with Marcel to see if he disagrees or if there's a factor I'm missing. For the future, I would still recommend filing an issue first and following the template. Discussions like this one get lost or forgotten if they happen as part of a patch. |
@bozaro thank you for raising this PR. If I can just, however, emphasise @mvdan's request:
The issue template for the CUE project is, like the Go project, carefully designed to help with the triaging process to make it easier for everyone (including project maintainers) to understand the nature of a bug or feature request. For a bug report, the questions Thanks again for contributing to the CUE project. |
Is there a chance to get this change in 0.6.0? |
We had to prioritise regressions and severe bugs like panics for v0.6.0, so I'm afraid not. We'll jump to v0.7 as soon as the final release is out, hopefully tomorrow, so I'll certainly look at this with Marcel soon. We would have of course liked to include more fixes into v0.6.0, but the more we try to include, the longer the release will take to be ready :) |
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.
Looked at this with @mpvl and we agree it's a good change :) Importing to Gerrit.
These tests should not change with an upcoming CL that to support pkg.Schema. Issue #2471 Signed-off-by: Marcel van Lohuizen <[email protected]> Change-Id: Ic941ea65432dfdd23743692c1e1efefc8de9da95 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1199623 TryBot-Result: CUEcueckoo <[email protected]> Unity-Result: CUE porcuepine <[email protected]> Reviewed-by: Daniel Martí <[email protected]>
An empty slice and a slice-typed nil have the same behaviour in most cases, but sometimes there are differences.
For example, when marshaling in
json.Marshal
.From my point of view, it is more correct to return an empty slice for an empty list instead of slice-typed nil.
https://go.dev/play/p/PfVuusup6UO
Source:
Output: