-
Notifications
You must be signed in to change notification settings - Fork 2
Fix: Ignore field/property initializers when SkipConstructor=true #146
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: Ignore field/property initializers when SkipConstructor=true #146
Conversation
Co-authored-by: dameng324 <4465571+dameng324@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #146 +/- ##
=======================================
Coverage 98.39% 98.39%
=======================================
Files 99 99
Lines 2186 2186
Branches 231 231
=======================================
Hits 2151 2151
Misses 23 23
Partials 12 12 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This comment has been minimized.
This comment has been minimized.
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.
Pull request overview
This PR fixes a bug where objects deserialized with SkipConstructor=true were incorrectly receiving field/property initializer values instead of default values. When SkipConstructor=true, the intent is to bypass all initialization logic, including both constructor execution and field/property initializers.
- Modified the code generator to only assign parsed values when they exist, allowing unset fields to remain at their default values
- Added comprehensive test coverage to verify the fix handles properties with initializers correctly
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/LightProto.Generator/LightProtoGenerator.cs | Changed GenSkipConstructor() to use conditional assignment instead of ternary operator with member.Initializer, ensuring unset fields get default values |
| tests/LightProto.Tests/Parsers/SkipConstructorWithInitializerTests.cs | Added new test class to verify that deserialized objects with SkipConstructor=true receive default values for unset proto members, not initializer values |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This comment has been minimized.
This comment has been minimized.
|
When
SkipConstructor=true, the constructor was bypassed usingGetUninitializedObject(), but field/property initializers were still executed. This resulted in deserialized objects receiving initializer values instead of defaults.Changes
GenSkipConstructor()to usedefaultinstead ofmember.Initializerwhen assigning unset fields during deserializationExample
Deserialized objects now receive true default values (null/0) for unset fields, consistent with the intent of bypassing all initialization logic.
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.