[bgen] Fix invalid code generation for delegate parameters without [BlockCallback]/[CCallback]. Fixes #10015. - #26495
Conversation
…lockCallback]/[CCallback] MakeTrampoline formatted the parameter's Type object directly into the generated invocation code, relying on Type.ToString(). For generic delegate types (e.g. Action<Action<bool>>), this produces CLR-style names such as System.Action + backtick + 1[System.Boolean], which is not valid C# and causes CS1056/CS1003/etc build errors when bgen generates the trampoline code. Use TypeManager.RenderType to correctly format the type as valid C# (e.g. global::System.Action<bool>). Fixes #10015 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Fixes an invalid bgen trampoline codegen case where a delegate parameter type was emitted using Type.ToString() (producing CLR-style generic names like System.Action\1[System.Boolean]), by rendering delegate types with TypeManager.RenderType` so generated C# is always syntactically valid.
Changes:
- Update trampoline invocation generation to use
TypeManager.RenderTypefor delegate-typed parameters. - Add a regression binding definition reproducing the
Action<Action<bool>>scenario. - Add an ErrorTests regression test that builds the temporary binding to ensure codegen succeeds.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/bgen/Generator.cs | Fixes trampoline code emission by rendering delegate types as valid C# syntax. |
| tests/bgen/tests/issue10015.cs | Adds a minimal binding definition that triggers the problematic nested generic delegate scenario. |
| tests/bgen/ErrorTests.cs | Adds a regression test to ensure bgen can build bindings containing the nested generic delegate type. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
| [Test] | ||
| [TestCase (Profile.iOS)] | ||
| public void Issue10015 (Profile profile) |
✅ API diff for current PR / commitNET (empty diffs)✅ API diff vs stableNET (empty diffs)ℹ️ Generator diffGenerator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes) Pipeline on Agent |
🔥 [CI Build #8066500] Test results 🔥Test results❌ Tests failed on VSTS: test results 1 tests crashed, 0 tests failed, 200 tests passed. Failures❌ Tests on macOS Ventura (13) tests🔥 Failed catastrophically on VSTS: test results - mac_ventura (no summary found). Html Report (VSDrops) Download Successes✅ assembly-processing: All 1 tests passed. Html Report (VSDrops) Download macOS tests✅ Tests on macOS Monterey (12): All 5 tests passed. Html Report (VSDrops) Download Linux Build VerificationPipeline on Agent |
MakeTrampoline formatted the parameter's Type object directly into the generated invocation code, relying on Type.ToString(). For generic delegate types (e.g.
Action<Action<bool>>), this produces CLR-style names such as System.Action + backtick + 1[System.Boolean], which is not valid C# and causes CS1056/CS1003/etc build errors when bgen generates the trampoline code.Use TypeManager.RenderType to correctly format the type as valid C# (e.g.
global::System.Action<bool>).Fixes #10015.