Add information to `IDeconstructionAssignmentOperation` about the conversions and methods involved when performing the operation.
- Dominant language
- C#
- Stars
- 20.7k
- Forks
- 4.3k
- PR merge metrics
- PR metrics pending
Description
## Background and Motivation
The IOp tree lacks information about what is happening in a deconstruction assignment like so:
```c#
(int a, int b) = x;
```
Specifically, the conversions involved and the potential target methods called. This has tripped up the IDE team which uses the IOp tree to determine things like which private methods of a type are used or not and can be removed.
We have it like that right now:
```csharp
public interface IDeconstructionAssignmentOperation : IAssignmentOperation
{
}
```
## Proposed API
Would be nice for the compiler to do the heavy lifting and get the symbol to the proper method being called:
```diff
///
/// The representation of a deconstruction as a tree of Deconstruct methods and conversions.
/// Methods only appear in non-terminal nodes. All terminal nodes have a Conversion.
///
/// Here's an example:
/// A deconstruction like (int x1, (long x2, long x3)) = deconstructable1 with
/// Deconstructable1.Deconstruct(out int y1, out Deconstructable2 y2) and
/// Deconstructable2.Deconstruct(out int z1, out int z2) is represented as 5 DeconstructionInfo nodes.
///
/// The top-level node has a (Deconstructable1.Deconstruct), no , but has two nodes.
/// Its first nested node has no , but has a (Identity).
/// Its second nested node has a (Deconstructable2.Deconstruct), no , and two nodes.
/// Those last two nested nodes have no , but each have a (ImplicitNumeric, from int to long).
///
public readonly struct CommonDeconstructionInfo
{
///
/// The Deconstruct method (if any) for this non-terminal position in the deconstruction tree.
///
public IMethodSymbol? Method { get; }
///
/// The conversion for a terminal position in the deconstruction tree.
///
public CommonConversion? Conversion { get; }
///
/// The children for this deconstruction node.
///
public ImmutableArray Nested { get; }
}
public interface IDeconstructionAssignmentOperation : IAssignmentOperation
{
+ CommonDeconstructionInfo DeconstructionInfo { get; }
}
namespace Microsoft.CodeAnalysis
{
public static class CSharpExtensions
{
+ public static DeconstructionInfo GetDeconstructionInfo(this IDeconstructionAssignment operation);
}
}
```
Contributor guide
Assessment
This issue has not been assessed yet.