Fix compatible-mode remap of pointer-to-fnptr-typedef fields#744
Merged
tannergooding merged 1 commit intoJul 13, 2026
Merged
Conversation
In compatible mode a function-pointer typedef is emitted as a managed delegate. GetTypeNameForPointeeType short-circuited a remapped typedef to a pointer of the remapped name, so a field pointing at such a typedef emitted a pointer to the managed delegate (e.g. PFoo*), which is invalid and produces CS8500 and forces the struct unsafe. Match the non-remapped path and emit IntPtr when ExcludeFnptrCodegen is set and the typedef's underlying type is a function type. Fixes dotnet#462 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.
In compatible mode (
ExcludeFnptrCodegen) a function-pointer typedef is emitted as a managed delegate.GetTypeNameForPointeeTypeshort-circuited a remapped typedef to a pointer of the remapped name, so a field pointing at such a typedef emitted a pointer to the managed delegate (e.g.PFoo*), which is invalid -- it producesCS8500and forces the containing structunsafe.Given:
with
--remap ApiCallbacks=Callbacks ApiPFoo=PFooin compatible mode.Before:
After (matches the no-remap case; the delegate is still renamed to
PFoo, only the field changes):The fix mirrors the non-remapped path: in the
wasRemappedbranch, whenExcludeFnptrCodegenis set and the typedef's underlying type is a function type, emitIntPtr. Theunsafemodifier drops automatically once the field isIntPtr.Scoped to compatible mode only. Latest/preview (function-pointer) codegen for remapped fnptr typedefs is intentionally untouched -- there's no named delegate there, so the correct rendering is a separate, ill-defined design question.
Added
FunctionPointerRemapTestcovering compatible Windows + Unix. Full generator suite passes (Failed: 0, Passed: 3726), zero golden churn.Fixes #462