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

Fix allownil propagated to byte slices as slice elements #374

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions _generated/omitempty.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ type OmitEmpty0 struct {

APtrNamedStr *NamedString `msg:"aptrnamedstr,omitempty"`

AString string `msg:"astring,omitempty"`
ANamedString string `msg:"anamedstring,omitempty"`
AByteSlice []byte `msg:"abyteslice,omitempty"`
AString string `msg:"astring,omitempty"`
ANamedString string `msg:"anamedstring,omitempty"`
AByteSlice []byte `msg:"abyteslice,omitempty"`
ASliceByteSlice [][]byte `msg:"aslicebyteslice,omitempty"`
AMapByteSlice map[string][]byte `msg:"amapbyteslice,omitempty"`

ASliceString []string `msg:"aslicestring,omitempty"`
ASliceNamedString []NamedString `msg:"aslicenamedstring,omitempty"`
Expand Down
8 changes: 8 additions & 0 deletions gen/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,14 @@ func (p *printer) closeblock() { p.print("\n}") }
// }
func (p *printer) rangeBlock(ctx *Context, idx string, iter string, t traversal, inner Elem) {
ctx.PushVar(idx)
// Tags on slices do not extend to the elements, so we always disable allownil on elements.
// If we want this to happen in the future, it should be a unique tag.
type an interface {
SetIsAllowNil(b bool)
}
if set, ok := inner.(an); ok {
set.SetIsAllowNil(false)
}
p.printf("\n for %s := range %s {", idx, iter)
next(t, inner)
p.closeblock()
Expand Down
2 changes: 1 addition & 1 deletion msgp/write_bytes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func BenchmarkAppendFloat(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
AppendFloat64(buf, src[i&(n-1)])
AppendFloat(buf, src[i&(n-1)])
}
}

Expand Down
Loading