Fix nil pointer dereference in ReflectFromType with ExpandedStruct (fix #163)#186
Merged
samlown merged 3 commits intoinvopop:mainfrom Apr 23, 2026
Merged
Conversation
When ExpandedStruct=true is combined with a non-struct reflect.Type (slice, map, interface, or enum-tagged field), definitions[name] is nil because only struct types register themselves via reflectStruct. The unconditional dereference at reflect.go:191 panics. Fall back to the base schema returned by reflectTypeToSchemaWithID when no definition was registered. Adds a regression test covering the affected type kinds and a fuzz test exercising ReflectFromType against a pool of types and Reflector flag combinations.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #186 +/- ##
==========================================
+ Coverage 89.30% 89.34% +0.04%
==========================================
Files 4 4
Lines 729 732 +3
==========================================
+ Hits 651 654 +3
Misses 59 59
Partials 19 19 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
samlown
requested changes
Apr 23, 2026
Contributor
samlown
left a comment
There was a problem hiding this comment.
Thanks for this! A few linter issues that I'll have a look at.
Contributor
We try, and actively use this in production, its just that time is very limited. Well tested PRs like this are great. |
# Conflicts: # reflect_test.go
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
samlown
approved these changes
Apr 23, 2026
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.
This PR fixes #163
I'm not 100% sure if this is still maintained, but I stumbled uppon what I believe is a bug or at least an unexpected behavior.
The impact for my app was fairly low (dev time), but unexpected.
Example reproducer based on your documentation example:
The fix is "just" checking that the key we are deleting exists.
I've added a fuzz test in addition of the regression test, in case we want to discover more bugs in the future (and possibly let agent fix them for you!). The fuzz-test, tests a few more flags combination to have more code coverage.