Support struct field type remapping via --with-type#751
Merged
tannergooding merged 1 commit intoJul 13, 2026
Merged
Conversation
Extend `--with-type` to accept a field-qualified key (`Struct.field=Type`) so the emitted type of an individual struct field can be overridden, reusing the existing `WithType` machinery. The original Clang type is preserved as a `[NativeTypeName]` attribute and unrelated fields are unaffected. The `*` catch-all is intentionally not honored for fields. Fixes dotnet#559 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
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.
Extends
--with-type(-wt) to accept a field-qualified key (Struct.field=Type) so the emitted type of an individual struct field can be overridden.#559originally proposed--remap-type Something.type=SomethingType, but--remap-type/--remap-fieldshipped in #736 with a different meaning (name disambiguation). Instead this reuses--with-type, whose semantics are already "use this type for the given declaration," soint Something.type;can be emitted asSomethingType Something.type;.Implementation reuses the existing
WithTypehelper, which already performs the override and preserves the original Clang type as a[NativeTypeName]attribute — it was previously wired only for enum backing types. Field type emission already flows through the sameGetRemappedTypeName(fieldDecl, …)path, so the hook is aFieldDeclsibling branch alongside the existingEnumDeclone.WithTypegains an optionalmatchStar = trueparameter; the enum call site is byte-for-byte unchanged.*catch-all is intentionally not honored for fields — rewriting every struct field to a single type is meaningless, so the qualifiedStruct.fieldkey must be explicit.[NativeTypeName]unless equivalent; unrelated fields are unaffected. This composes with the existing macro/enum-backing/struct-marker uses of--with-type, which use distinct qualified names.Added a focused root-level regression fixture (
WithTypeFieldTest) usingValidateGeneratedCSharpLatestWindowsBindingsAsync, rather than adding to the 16-way matrix, to avoid golden churn. It assertsint type→public SomethingType type;with[NativeTypeName("int")]and that a siblingint other;field is untouched. No existing goldens change.Validation:
dotnet build -c Releaseproduces 0 warnings;dotnet test -c Releaseis green (3746 generator + 56 interop/3 skipped + 11 CLI-parser tests).Fixes #559