Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect diagnostic that Deconstruct method is unused. #75995

Closed
gafter opened this issue Nov 20, 2024 · 5 comments · Fixed by #76012
Closed

Incorrect diagnostic that Deconstruct method is unused. #75995

gafter opened this issue Nov 20, 2024 · 5 comments · Fixed by #76012
Assignees
Labels
Area-IDE help wanted The issue is "up for grabs" - add a comment if you are interested in working on it
Milestone

Comments

@gafter
Copy link
Member

gafter commented Nov 20, 2024

Roslyn reports that Deconstruct is unused in the C# code below. But it is used. You would get an error if you remove the method.

class C
{
    void M(
        ref object o,
        ref object p)
    {
        (o, p) = this;
    }
    
    void Deconstruct(
        out object? o,
        out object? p)
    {
        o = null;
        p = null;
    }
}
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Nov 20, 2024
@CyrusNajmabadi
Copy link
Member

@gafter are you getting a compiler warning, or an analyzer warning? If so, can you include the diagnostic id?

@CyrusNajmabadi CyrusNajmabadi self-assigned this Nov 21, 2024
@CyrusNajmabadi CyrusNajmabadi added this to the Backlog milestone Nov 21, 2024
@dotnet-policy-service dotnet-policy-service bot removed the untriaged Issues and PRs which have not yet been triaged by a lead label Nov 21, 2024
@github-project-automation github-project-automation bot moved this to InQueue in Small Fixes Nov 21, 2024
@gafter
Copy link
Member Author

gafter commented Nov 21, 2024

@gafter gafter changed the title Incorrect warning that Deconstruct method is unused. Incorrect diagnostic that Deconstruct method is unused. Nov 21, 2024
@jcouv
Copy link
Member

jcouv commented Nov 21, 2024

I see that diagnostic too (IDE0051)
Image

@CyrusNajmabadi CyrusNajmabadi added help wanted The issue is "up for grabs" - add a comment if you are interested in working on it and removed Area-Compilers labels Nov 21, 2024
@CyrusNajmabadi
Copy link
Member

@jcouv I can't figure out how to determine that the .Deconstruct method is used here. How is this exposed in teh semantic model? Also checking with @333fred . I do see a IDeconstructAssignmentOperation, but it seems to be missing the target method, unless i'm missing something. Could you guys advise? How do you encode this into the tree?

@jcouv
Copy link
Member

jcouv commented Nov 21, 2024

There's an issue tracking adding this information to IDeconstructAssignmentOperation: #74757
Otherwise, GetDeconstructionInfo and GetDeconstructionInfo on semantic model currently should have the information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE help wanted The issue is "up for grabs" - add a comment if you are interested in working on it
Projects
Status: Completed
Development

Successfully merging a pull request may close this issue.

3 participants