roslyn icon indicating copy to clipboard operation
roslyn copied to clipboard

Add `IMethodSymbol Deconstruct` to `IDeconstructionAssignmentOperation`

Open B1Z0N opened this issue 1 year ago • 1 comments

Background and Motivation

We have it like that right now:

    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:

    public interface IDeconstructionAssignmentOperation : IAssignmentOperation
    {
+       IMethodSymbol Deconstruct;
    }

PS: I simplified the issue scheme because it's far too simple of a change. What do you think?

B1Z0N avatar Aug 14 '24 11:08 B1Z0N

PS: I simplified the issue scheme because it's far too simple of a change. What do you think?

@B1Z0N could you please fill out the entire template? Every change needs a justification; what is the scenario you're trying to use this in? What do you have to write today? How would this API change that?

333fred avatar Aug 20 '24 20:08 333fred

Championing this. IDE needs this in analyzers like the "remove unused members" analyzer to know that the .Deconstruct method is actually used.

CyrusNajmabadi avatar Nov 21 '24 20:11 CyrusNajmabadi

That said, it seems like we need to expose something more like DeconstructInfo which ahs the target, as well as deep nested info about conversions

CyrusNajmabadi avatar Nov 21 '24 20:11 CyrusNajmabadi

Ok. I ahve updated the proposal. It adds a CommonDeconstructionInfo which maps to the C# specific DeconstructionInfo: https://github.com/dotnet/roslyn/blob/main/src/Compilers/CSharp/Portable/Compilation/DeconstructionInfo.cs. Just like the C# version, it exposes the 'Method' and 'Conversion' (though as a CommonConversion as we're in the common layer), as well as nested infos.

CyrusNajmabadi avatar Nov 21 '24 20:11 CyrusNajmabadi

@CyrusNajmabadi we have extension methods for getting C# and VB specific conversions off an IConversionOperation; do you want to propose similar extensions for getting language-specific deconstruction info?

333fred avatar Nov 21 '24 21:11 333fred

That makes a lot of sense @333fred . will update.

CyrusNajmabadi avatar Nov 21 '24 22:11 CyrusNajmabadi

API Review

  • Could we just have the extension method?
    • Wouldn't work well. The pain point is that we have to do language-specifics
  • Names look good and match up with existing public API for DeconstructionInfo.
  • If we need to, we'll look at calculating for CommonDeconstructionInfo lazily to avoid expensive work.

Conclusion: Approved

333fred avatar Dec 05 '24 21:12 333fred