Skip to content

RCS1258 Enum flag already contained: reported if only one bit matches #1739

Description

@ovska

To trigger RCS1258, it seems like only one bit needs to match between the flags. Below is a reproduction, Test1 shows the fix suggestion, Test2 is after, and some example input where they return different values before and after the fix.

using System;

public class Program
{
    public static void Main()
    {
        Console.WriteLine(C.Test1(FooBar.Bar));
        Console.WriteLine(C.Test2(FooBar.Bar));
    }

    [System.Flags]
    internal enum FooBar
    {
        None = 0,
        Shared = 1,
        Foo = Shared | 2,
        Bar = Shared | 4,
    }

    class C
    {
        // before fixer
        public static bool Test1(FooBar x)
        {
            return x == (FooBar.Foo | FooBar.Bar);
        }

        // after fixer
        public static bool Test2(FooBar x)
        {
            return x == (FooBar.Bar);
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions