Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
josefpihrt committed Oct 11, 2024
1 parent 136fada commit 40b1333
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -183,26 +183,4 @@ private static void AnalyzeInvocationExpression(SyntaxNodeAnalysisContext contex
invocation,
"bitwise operator");
}

private static bool IsConstantAndCompositeEnumValue(
SyntaxNode node,
SemanticModel semanticModel,
CancellationToken cancellationToken = default)
{
var enumTypeSymbol = (INamedTypeSymbol)semanticModel.GetTypeSymbol(node, cancellationToken);

if (enumTypeSymbol?.EnumUnderlyingType is not null)
{
Optional<object> constantValue = semanticModel.GetConstantValue(node, cancellationToken);

if (constantValue.HasValue)
{
ulong value = SymbolUtility.GetEnumValueAsUInt64(constantValue.Value!, enumTypeSymbol);

return FlagsUtility<ulong>.Instance.IsComposite(value);
}
}

return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -271,25 +271,24 @@ bool M(int value)
}

[Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.UseHasFlagMethodOrBitwiseOperator)]
public async Task TestNoDiagnostic_NotEnumType2()
public async Task TestNoDiagnostic_NotConstant()
{
await VerifyNoDiagnosticAsync(@"
using System.IO;
class P
{
private FileAttributes _skipMask = FileAttributes.Device | FileAttributes.Offline;
private FileAttributes _flags = FileAttributes.Device | FileAttributes.Offline;
void M()
{
var fileAttr = FileAttributes.Device;
var flag = FileAttributes.Device;
if ((fileAttr & _skipMask) != 0)
if ((flag & _flags) != 0)
{
}
}
}
");
}

}

0 comments on commit 40b1333

Please sign in to comment.