Fix CCW detection for constructor parameters - #2339
Merged
Merged
Conversation
…r CCW generation The AOT source generator's lookup table code path only handled InvocationExpressionSyntax (regular method calls) when analyzing arguments to detect managed types that need CCW vtable entries. It did not handle BaseObjectCreationExpressionSyntax (constructor calls like 'new WinRTType(args)'). This meant that when a managed generic collection type (e.g. List<KeyValuePair<string, string>>) was passed as an argument to a WinRT constructor (e.g. new HttpFormUrlEncodedContent(pairs)), the source generator would not detect it and would not generate the necessary CCW entries. At runtime, this caused a 'Failed to create a CCW' error. The fix adds BaseObjectCreationExpressionSyntax handling to both NeedVtableOnLookupTable (syntactic filter) and GetVtableAttributesToAddOnLookupTable (semantic analysis), mirroring the existing InvocationExpressionSyntax logic. Fixes #2337 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes issue #2337 by updating the WinRT AOT source generator’s CCW/vtable detection logic to also analyze arguments passed to constructors (object creation expressions), not just regular method invocations. This ensures generic managed collections passed into WinRT constructors trigger generation of the required CCW vtable entries.
Changes:
- Extend lookup-table detection to include constructor argument analysis (
new SomeWinRTType(arg)). - Add regression coverage in functional collections tests to validate constructor-argument CCW detection.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/Tests/FunctionalTests/Collections/Program.cs | Adds a regression test that passes a generic managed collection into a WinRT runtimeclass constructor and validates enumeration works. |
| src/Authoring/WinRT.SourceGenerator/AotOptimizer.cs | Updates the AOT optimizer to treat object creation expressions with arguments like invocations and extract argument types for vtable attribute generation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…tors Adds two regression tests for #2337 that exercise the new BaseObjectCreationExpressionSyntax handling in the AOT source generator: 1. LinkedList<int> (declared with 'var') passed to CustomIterableTest constructor - uses a type not used elsewhere in the test, ensuring the CCW generation is only triggered through the constructor argument analysis path. 2. List<KeyValuePair<string, string>> (declared with 'var') passed to HttpFormUrlEncodedContent constructor - exact repro from the issue, matching the reported scenario. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sergio0694
force-pushed
the
fix/ccw-constructor-args-2337
branch
from
March 17, 2026 00:04
59dd6c8 to
ea4cc97
Compare
manodasanW
approved these changes
Mar 17, 2026
manodasanW
added a commit
that referenced
this pull request
Apr 30, 2026
Port of test additions from master commit d7bcbb0. While the 2.x source fix (AotOptimizer.cs) doesn't apply to 3.0 (the interop generator does whole-app IL analysis), these regression tests validate that generic managed collections passed to WinRT constructors get proper CCW marshalling support: 1. LinkedList<int> passed to CustomIterableTest constructor 2. List<KeyValuePair<string, string>> passed to HttpFormUrlEncodedContent Co-authored-by: Copilot <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.
Fixes #2337. We were not analyzing arguments to constructors specifically.