Repository navigation
fix(encoder): guard the IsZeroer check with CanInterface in omitempty - #970
Open
prostomarkeloff wants to merge 1 commit into
Open
prostomarkeloff wants to merge 1 commit into
prostomarkeloff wants to merge 1 commit into
Conversation
isOmittedByOmitEmptyTag called v.Interface().(IsZeroer) without the `if v.CanInterface()` guard its twin isOmittedByOmitZero has, so Marshal panicked on a struct embedding an unexported type tagged `,omitempty` (reflect: cannot return value obtained from unexported field or method). Wrap the assertion in CanInterface, mirroring the omitzero path.
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #970 +/- ##
=======================================
Coverage 80.65% 80.66%
=======================================
Files 22 22
Lines 6845 6846 +1
=======================================
+ Hits 5521 5522 +1
Misses 905 905
Partials 419 419 🚀 New features to boost your workflow:
|
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.
Found with find-dup-defs using its converge pass, which flagged
isOmittedByOmitZeroandisOmittedByOmitEmptyTagas near-duplicate helpers diverging on one guard.encode.goisOmittedByOmitEmptyTagcallsv.Interface().(IsZeroer)directly. Its twinisOmittedByOmitZerowraps the same call inif v.CanInterface(). A value reached by traversing an embedded unexported struct field is not interfaceable, soyaml.Marshalof such a type tagged,omitemptypanics withreflect: cannot return value obtained from unexported field or method. Theomitzerosibling marshals the same type fine, which is what pointed at the missing guard.Fix: wrap the
IsZeroerassertion inif v.CanInterface(), mirroringisOmittedByOmitZero.Added a regression test marshaling a struct that embeds an unexported type tagged
,omitempty; it panics before the change and passes after.Disclosure: prepared with the help of an AI tool; I have reviewed the change and test and understand each line.