fix: resolve oneof enum name collisions with nested types#34
Open
th0114nd wants to merge 2 commits intoanthropics:mainfrom
Open
fix: resolve oneof enum name collisions with nested types#34th0114nd wants to merge 2 commits intoanthropics:mainfrom
th0114nd wants to merge 2 commits intoanthropics:mainfrom
Conversation
) When a oneof's PascalCase name collides with a nested message or enum name in the same module, suffix the oneof enum with "Oneof" instead of returning a hard NestedTypeOneofConflict error. This unblocks protos like riderperks PerkRestrictions (message RegionCodes + oneof region_codes). The suffix is applied consistently across all code paths: struct fields, enum definitions, view enums, binary encode/decode, text format, and JSON serde. If the suffixed name also collides (pathological case), an OneofSuffixConflict error is returned. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Made-with: Cursor
|
All contributors have signed the CLA ✍️ ✅ |
Author
|
I have read the CLA Document and I hereby sign the CLA |
4 tasks
When a nested type triggers the `Oneof` suffix for one oneof enum (e.g., `my_field` → `MyFieldOneof`), a second oneof named `my_field_oneof` would also produce `MyFieldOneof`, creating duplicate type names. Introduce `resolve_oneof_idents` which processes oneofs sequentially, growing the reserved set after each allocation. All call sites now look up pre-computed idents instead of independently calling `oneof_enum_ident`, ensuring consistency across struct fields, binary encode/decode, text format, JSON serde, and view generation. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Made-with: Cursor
Author
|
Added a follow-up commit addressing a code review finding: sequential oneof ident allocation to prevent sibling oneofs from claiming the same suffixed name. Example: nested message |
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.
Summary
Fixes #31.
When a protobuf message has a nested type (message or enum) whose PascalCase name collides with a oneof enum's PascalCase name, the codegen now suffixes the oneof enum with
Oneofinstead of returning a hardNestedTypeOneofConflicterror.oneof region_codes+message RegionCodes→ generatesRegionCodesOneofenumoneof my_field+message MyField→ generatesMyFieldOneofenumOneofSuffixConflicterror is returnedThe suffix is applied consistently across all code paths: struct field types, enum definitions, view enums (
MyFieldOneofView), binary encode/decode, text format, and JSON serde.Changes
oneof.rs: Addedreserved_names_for_msg()helper and modifiedoneof_enum_ident()to accept a reserved name set and suffix withOneofon collisionmessage.rs: Builds reserved set, threads throughoneof_enum_identcall sitesimpl_message.rs,impl_text.rs,view.rs: Threadmsgparameter to compute reserved names at eachoneof_enum_identcall sitelib.rs: Removedcheck_nested_type_oneof_conflicts()upfront validation andNestedTypeOneofConflicterror variant; addedOneofSuffixConflictfor pathological double-collision casetests/naming.rs: Converted error-asserting test to success-asserting withOneofsuffix check; added tests for nested enum collision, view suffix propagation, and double-collision errorTest plan
test_nested_type_oneof_conflict_resolved_with_suffix— nested message + oneof collision generatesMyFieldOneoftest_nested_enum_oneof_conflict_resolved_with_suffix— nested enum + oneof collision (gh#31 example) generatesRegionCodesOneoftest_nested_type_oneof_conflict_view_uses_suffix— view enum usesMyFieldOneofViewtest_oneof_suffix_double_collision_errors— pathological case errors cleanlycargo testpasses (233 tests)cargo clippy --workspace -- -D warningscleanMade with Cursor