Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public override void Initialize(AnalysisContext context)
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze);

context.RegisterSymbolAction(Utils.DebuggableWrapper(AnalyzeNode), SymbolKind.Method);
context.RegisterOperationAction(Utils.DebuggableWrapper(AnalyzeOperation), OperationKind.LocalFunction, OperationKind.AnonymousFunction);
context.RegisterOperationAction(Utils.DebuggableWrapper(AnalyzeOperation), OperationKind.LocalFunction);
}

private static void AnalyzeNode(SymbolAnalysisContext context)
Expand All @@ -74,17 +74,7 @@ private static void AnalyzeOperation(OperationAnalysisContext context)
{
if (context.Operation is ILocalFunctionOperation localFunctionOperation)
{
AnalyzeSymbol(localFunctionOperation.Symbol);
}
else if (context.Operation is IAnonymousFunctionOperation anonymousFunctionOperation)
{
AnalyzeSymbol(anonymousFunctionOperation.Symbol);
}

return;

void AnalyzeSymbol(IMethodSymbol methodSymbol)
{
IMethodSymbol methodSymbol = localFunctionOperation.Symbol;
if (methodSymbol.IsAsync && methodSymbol.ReturnsVoid)
{
context.ReportDiagnostic(Diagnostic.Create(Descriptor, methodSymbol.Locations[0]));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,44 +42,6 @@ async void F() {}
await Verify.VerifyAnalyzerAsync(test, expected);
}

[Fact]
public async Task ReportWarningOnAsyncVoidLambda()
Comment thread
AArnott marked this conversation as resolved.
Resolved
{
var test = @"
using System;
using System.Threading.Tasks;

class Test {
void M() {
F(async () => await Task.Delay(0));

void F(Action a) {}
}
}
";
CodeAnalysis.Testing.DiagnosticResult expected = Verify.Diagnostic().WithLocation(7, 11);
await Verify.VerifyAnalyzerAsync(test, expected);
}

[Fact]
public async Task ReportWarningOnAsyncVoidDelegate()
{
var test = @"
using System;
using System.Threading.Tasks;

class Test {
void M() {
F(async delegate() { await Task.Delay(0); });

void F(Action a) {}
}
}
";
CodeAnalysis.Testing.DiagnosticResult expected = Verify.Diagnostic().WithLocation(7, 11);
await Verify.VerifyAnalyzerAsync(test, expected);
}

[Fact]
public async Task ReportWarningOnAsyncVoidMethodSimilarToAsyncEventHandler()
{
Expand Down