Skip to content

Fix S1144 FP: Ignore unused Deconstruct methods #3842

@andrei-epure-sonarsource

Description

This is a follow-up of #2478

    public class ReproIssue2478
    {
        public void SomeMethod()
        {
            ForSwitchArm x = null;
            var result = (x) switch
            {
                null => 1,
                // normally, when deconstructing in a switch, we don't actually know the type
                (object x1, object x2) => 2
            };
            var y = new ForIsPattern();
            if (y is (string a, string b)) { }
        }

        private sealed class ForSwitchArm
        {
            public void Deconstruct(out object a, out object b) { a = b = null; } // Noncompliant FP
        }

        private sealed class ForIsPattern
        {
            public void Deconstruct(out string a, out string b) { a = b = null; } // Noncompliant FP
        }
    }

Metadata

Metadata

Labels

False PositiveRule IS triggered when it shouldn't be.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions