Uh oh!
There was an error while loading. Please reload this page.
Strip partial and virtual modifiers from generated COM interface method stubs - #126719
Conversation
…d VtableIndexStubGenerator The ComInterfaceGenerator and VtableIndexStubGenerator were copying the partial modifier from user-declared interface methods to the generated stub code, producing invalid C#. This change strips the partial keyword from method modifiers when creating the method syntax template, similar to how the new keyword and accessibility modifiers are already stripped. Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/de757761-5c54-412d-9875-7403edd00714 Co-authored-by: jtschuster <36744439+jtschuster@users.noreply.github.com>
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Jackson Schuster <36744439+jtschuster@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR updates the COM interface source generators to avoid emitting invalid C# when user-declared COM interface methods include the partial modifier, by stripping partial from copied method modifiers and adding a regression compilation test.
Changes:
- Strip
SyntaxKind.PartialKeywordfrom copied method modifiers inComInterfaceGeneratorandVtableIndexStubGenerator. - Add a regression test ensuring partial method modifiers on
[GeneratedComInterface]methods don’t break generated code compilation.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/Compiles.cs | Adds a new compilation regression test for partial method modifiers on COM interface methods. |
| src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/VtableIndexStubGenerator.cs | Filters out partial from method modifiers when constructing the syntax template for generated stubs. |
| src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceGenerator.cs | Filters out partial (alongside existing new filtering) from method modifiers used in generated stubs. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
This comment has been minimized.
This comment has been minimized.
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Jackson Schuster <36744439+jtschuster@users.noreply.github.com>
Uh oh!
There was an error while loading. Please reload this page.
🤖 Copilot Code Review — PR #126719Note This review was generated by Copilot (Claude Opus 4.6). A GPT-5.4 sub-agent was launched in parallel but did not return within the timeout window; this review reflects a single-model analysis. Holistic AssessmentMotivation: Justified. When a user declares a Approach: Correct and consistent with established patterns. The Summary: ✅ LGTM. The fix is correct, minimal, and well-tested for the primary code path. One minor test coverage observation below (non-blocking). Detailed Findings✅ Correctness — Partial modifier stripping is correctThe generated methods are explicit interface implementations (via ✅ Test — The test validates the fix for ComInterfaceGeneratorThe new 💡 Test coverage — VtableIndexStubGenerator path not directly testedThe fix modifies both 💡 Pre-existing inconsistency — |
Uh oh!
There was an error while loading. Please reload this page.
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/82488d5d-6c3d-426f-9d23-9e5eb6e75992 Co-authored-by: jtschuster <36744439+jtschuster@users.noreply.github.com>
jtschuster
commented
Apr 14, 2026
/ba-g failures unrelated |
Description
ComInterfaceGeneratorandVtableIndexStubGeneratorcopy method modifiers from user-declared interface methods into generated stub code. Thenewkeyword and accessibility modifiers were already stripped, butpartialandvirtualwere not — producing invalid C# when the user declares partial or virtual methods on a[GeneratedComInterface]interface.Changes:
ComInterfaceGenerator.cs: FilterSyntaxKind.PartialKeywordandSyntaxKind.VirtualKeywordalongside existingNewKeywordfilter inCalculateStubInformationVtableIndexStubGenerator.cs: AddPartialKeywordandVirtualKeywordfilters to modifier stripping inCalculateStubInformationCompiles.cs: Add regression test confirming partial and virtual method modifiers don't produce invalid generated codeNote:
LibraryImportGeneratorandDownlevelLibraryImportGeneratorare intentionally unchanged — they generate partial method implementations wherepartialmust be preserved.