Repository navigation
Conversation
encodeArray passed walkValue's zero Value for a nil *T element to encodeStruct, which panicked in reflect.Value.Type. Unmarshal into [N]*T leaves the elements past the last record nil, so Marshal of that value panicked. A nil element now writes no record.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
MarshalandEncoder.Encodepanic on a[]*Tor[N]*Tthat contains a nil element:encodeArraypasses the zeroreflect.ValuefromwalkValuetoencodeStruct, which callsv.Type().Unmarshalinto[N]*Tleaves the elements past the last record nil (asTestUnmarshalexpects), so a round trip crashes:With this change a nil element writes no record, so the example returns
"Name,Age\nalice,30\nbob,25\n", the same CSV it was decoded from. Writing an empty row or returning anInvalidEncodeErrorwould also work if you prefer either; skipping is the one that round-trips.Checklist
go test -race ./...; the new cases panic on master)Written with AI assistance (Claude); I have reviewed the change.