Skip to content

Fix S2589 FN: Tuple binary operations (comparison) #8486

@zsolt-kolbay-sonarsource

Description

Description

S2589 doesn't work with binary tuple operations, resulting in FNs.

Repro steps

public class Repro_8486
{
    public void Method()
    {
        string text1 = SomeString();
        string text2 = SomeString();
        if ((text1, text2) == (null, null) && text1 != null)          // FN
        {
            Console.WriteLine();
        }
        if ((text1, text2) != (null, null) && text1 == null)          // FN
        {
            Console.WriteLine();
        }
        if ((text1, text2) != (SomeString(), null) && text1 == null)  // Compliant
        {
            Console.WriteLine();
        }

        string text3 = null;
        string text4 = "";
        string text5 = SomeString();
        if ((text3, text4) == (null, null))                      // FN
        {
            Console.WriteLine();
        }
        if ((text3, text4) != (null, null))                      // FN
        {
            Console.WriteLine();
        }
        if ((text3, text5) == (null, null))                      // Compliant
        {
            Console.WriteLine();
        }
    }

    private string SomeString() => "";
}

Expected behavior

S2589 should be raised.

Actual behavior

No issue is raised.

Implementation details

The rule itself doesn't need fixing. A Processor must be created for BinaryTupleOperation.

Related information

  • C#/VB.NET Plugins version: 9.15
  • Visual Studio version: 17.8.3
  • Operating System: Windows 10

Metadata

Metadata

Labels

False NegativeRule is NOT triggered when it should be.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions