Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed

- Fix enum contained flags check for partial matches in [RCS1258](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1258) ([PR](https://github.com/dotnet/roslynator/pull/1740) by @ovska)

## [4.15.0] - 2025-12-14

### Added
Expand Down
3 changes: 2 additions & 1 deletion src/Analyzers/CSharp/Analysis/UnnecessaryEnumFlagAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ private static void AnalyzeBitwiseOrExpression(SyntaxNodeAnalysisContext context
for (int i = values.Count - 1; i >= 0; i--)
{
(ExpressionSyntax expression2, ulong value2) = values[i];
ulong sharedBits = value & value2;

if ((value & value2) != 0)
if (sharedBits == value2 || sharedBits == value)
{
if (value <= value2)
{
Expand Down
24 changes: 24 additions & 0 deletions src/Tests/Analyzers.Tests/RCS1258UnnecessaryEnumFlagTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,28 @@ void M()
}
");
}

[Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.UnnecessaryEnumFlag)]
public async Task TestNoDiagnostic_PartiallySame()
{
await VerifyNoDiagnosticAsync(
@"
[System.Flags]
enum FooBar
{
Shared = 1,
Foo = Shared | 2,
Bar = Shared | 4,
}

class C
{
public static bool M(FooBar x)
{
return x == (FooBar.Foo | FooBar.Bar);
}
}
"
);
}
}
Loading