diff --git a/src/Microsoft.VisualStudio.Threading.Analyzers/CommonInterest.cs b/src/Microsoft.VisualStudio.Threading.Analyzers/CommonInterest.cs index 42300094c..ef21f9f90 100644 --- a/src/Microsoft.VisualStudio.Threading.Analyzers/CommonInterest.cs +++ b/src/Microsoft.VisualStudio.Threading.Analyzers/CommonInterest.cs @@ -279,7 +279,7 @@ public static bool IsAwaitable(this ITypeSymbol? typeSymbol, SemanticModel seman { while (operation?.Parent is not null) { - if (operation.Parent is IAnonymousFunctionOperation or IMethodBodyOperation) + if (operation.Parent is IAnonymousFunctionOperation or IMethodBodyOperation or ILocalFunctionOperation) { return operation.Parent; } diff --git a/test/Microsoft.VisualStudio.Threading.Analyzers.Tests/VSTHRD110ObserveResultOfAsyncCallsAnalyzerTests.cs b/test/Microsoft.VisualStudio.Threading.Analyzers.Tests/VSTHRD110ObserveResultOfAsyncCallsAnalyzerTests.cs index bae3ec25c..03dfc29b2 100644 --- a/test/Microsoft.VisualStudio.Threading.Analyzers.Tests/VSTHRD110ObserveResultOfAsyncCallsAnalyzerTests.cs +++ b/test/Microsoft.VisualStudio.Threading.Analyzers.Tests/VSTHRD110ObserveResultOfAsyncCallsAnalyzerTests.cs @@ -485,4 +485,34 @@ class Class1 await CSVerify.VerifyAnalyzerAsync(test); } + + [Fact] + public async Task LocalVoidFunctionWithinAsyncTaskMethod() + { + string test = /* lang=c#-test */ """ + using System.Threading.Tasks; + + class Test + { + async Task DoOperationAsync() + { + DoOperationInner(); + + void DoOperationInner() + { + [|HelperAsync()|]; + } + } + + void DoOperation() + { + [|HelperAsync()|]; + } + + Task HelperAsync() => Task.CompletedTask; + } + """; + + await CSVerify.VerifyAnalyzerAsync(test); + } }