Fix tuple pattern matching in AotConverterGenerator to use ValueTuple types #2799
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.
The AotConverterGenerator was generating incorrect pattern matching code for tuple types, causing compilation errors when using implicit operators with tuple parameters.
Problem
When generating AOT converters for implicit operators that accept tuple parameters like
(int Value1, int Value2), the generator was creating positional patterns:This syntax is interpreted as a positional pattern that looks for a
Deconstructmethod on theobjecttype, which doesn't exist, resulting in compilation errors:Solution
The fix detects when the source type is a tuple type using
IsTupleTypeand generates the correctValueTuple<T1, T2, ...>pattern matching syntax instead:This works correctly because it pattern matches against the actual underlying
ValueTupletype rather than using tuple literal syntax that gets interpreted as a positional pattern.Example
This code now compiles successfully:
The fix handles tuple types of any arity (2-tuple, 3-tuple, etc.) and maintains backward compatibility with existing non-tuple conversion operators.
Fixes #2798.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.