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

RCS1096 incorrectly identifies/converts HasFlag logic #720

Closed
qbert09 opened this issue Sep 16, 2020 · 1 comment
Closed

RCS1096 incorrectly identifies/converts HasFlag logic #720

qbert09 opened this issue Sep 16, 2020 · 1 comment

Comments

@qbert09
Copy link

qbert09 commented Sep 16, 2020

Product and Version Used:
When running the conversion for RCS1096 it incorrectly converts the HasFlag logic. The current conversion treats composite flags as though HasFlag is identifying that any of the bits is set, where as in reality HasFlag will only return true if all bits are set.

Here is a sample program to demonstrate:
https://rextester.com/RENET59796

Steps to Reproduce:
given an enumeration and a variable x:

public enum MyFlags
{
    A = 1,
    B = 2,
    C = 4,
    D = 8,
    DA = D | A
}

var x = MyFlags.A | MyFlags.C;

if I apply the fix for RCS1096 and code:

if(x.HasFlag(MyFlags.A|MyFlags.C))
{
    //...
}

I get:

if((x & (MyFlags.A|MyFlags.C)) != 0)
{
    //...
}

When I would expect:

if((x & (MyFlags.A|MyFlags.C)) == (MyFlags.A|MyFlags.C))
{
    //...
}
@josefpihrt
Copy link
Collaborator

Thanks for the report @qbert09 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants