Skip to content

Commit

Permalink
[Fix] Fixes incorrect warnings on ConcurrentSet.Update (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
akade authored Jul 16, 2023
1 parent f5d7646 commit ba44b57
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
25 changes: 25 additions & 0 deletions Analyzers/Akade.IndexedSet.Analyzers.Test/SimpleAnalyzerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,29 @@ public async Task Do_not_use_block_bodied_lambda_Async()

await VerifyCS.VerifyAnalyzerAsync(code, name);
}

[TestMethod]
public async Task No_diagnostic_reported_for_concurrent_set_update()
{
string code = $$"""
using Akade.IndexedSet;
using Akade.IndexedSet.Concurrency;
ConcurrentIndexedSet<int> test = new[]{5,10,20}.ToIndexedSet()
.WithIndex(x => x)
.BuildConcurrent();
test.Update(set => {
set.Add(1);
set.Add(2);
});
test.Update((set, state) => {
set.Add(3);
set.Add(4);
}, 8);
""";

await VerifyCS.VerifyAnalyzerAsync(code);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ private void AnalyzeNode(SyntaxNodeAnalysisContext context)
&& namedType.IsGenericType
&& _relevantTypes.Contains(namedType.OriginalDefinition))
{
if (node.ArgumentList.Arguments.FirstOrDefault()?.Expression is LambdaExpressionSyntax lambda)
if (node.ArgumentList.Arguments.FirstOrDefault()?.Expression is LambdaExpressionSyntax lambda
&& !IsExcludedMethod(memberAccess.Name.Identifier))
{
CheckParameterName(context, lambda);
CheckForParenthesized(context, lambda);
Expand All @@ -90,6 +91,11 @@ private void AnalyzeNode(SyntaxNodeAnalysisContext context)
}
}

private bool IsExcludedMethod(SyntaxToken identifier)
{
return identifier.ValueText is "Update";
}

private void CheckForBlockBodiedLambda(SyntaxNodeAnalysisContext context, LambdaExpressionSyntax lambda)
{
if (lambda.Block != null)
Expand Down

0 comments on commit ba44b57

Please # to comment.