fix: qualify Option in nested scopes to prevent prelude shadowing (#36)#39
Draft
th0114nd wants to merge 6 commits intoanthropics:mainfrom
Draft
fix: qualify Option in nested scopes to prevent prelude shadowing (#36)#39th0114nd wants to merge 6 commits intoanthropics:mainfrom
th0114nd wants to merge 6 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
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
When a oneof's PascalCase name matches the parent message name (e.g.
message DataType { oneof data_type { ... } }), the generated oneof enum
shadows the parent struct imported via use super::*. Include the parent
message name in the reserved set so the oneof enum gets the Oneof suffix
(DataTypeOneof), preventing the shadow.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Made-with: Cursor
…ng (anthropics#32) When a user-defined message `FooView` exists alongside `Foo`, the generated `FooView<'a>` view type for `Foo` would collide. Previously this was a hard `ViewNameConflict` error blocking the entire crate. Now the codegen skips generating the view for `Foo` and continues. The user-defined `FooView` message (and its own view `FooViewView`) are generated normally. Downstream code that references `Foo`'s view will get a targeted compile error rather than a blanket codegen failure. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Made-with: Cursor
…thropics#36) When a proto message named `Option` is nested inside another message, the generated `pub struct Option` shadows `core::option::Option` in the parent module scope. This caused struct fields like `pub value: Option<option::Value>` to resolve to the proto struct (0 generic args) instead of the standard library type. Fix: extend ImportResolver with `child_for_message()` to propagate blocked prelude names through the `use super::*` module chain. Each recursive `generate_message` call now receives a child resolver that accounts for sibling types in its module scope. Also qualify bare `Option` in custom deserialize temporaries and `skip_serializing_if` predicates. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Made-with: Cursor
When multiple protos share a package and are include!d into one Rust module, a top-level message Option in one file shadows std's Option for siblings. Union prelude-blocked names per protobuf package (not the whole batch) so other packages in the same generate() call still emit bare Option. Add regression tests for same-package cross-file shadowing and for isolation across packages. Made-with: Cursor
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 #36 — a proto message named
Optionshadowscore::option::Option, causing type errors on oneof fields in nested scopes.ImportResolverwithchild_for_message()to propagate blocked prelude names through theuse super::*module chaingenerate_messagecall now receives a child resolver that accounts for sibling types in its module scopeOptionin custom deserialize temporaries andskip_serializing_ifpredicatesOptionmessage scenariosTest plan
cargo test -p buffa-codegen(239 tests pass)cargo test --workspace(all pass)cargo clippy --workspace --all-targets(clean)Made with Cursor