Skip to content

Commit

Permalink
Merge pull request #1385 from microsoft/fix1363
Browse files Browse the repository at this point in the history
Fix VSTHRD110 false negative in local functions of async methods
  • Loading branch information
AArnott authored Feb 6, 2025
2 parents f8b0a4f + 50873c3 commit c7d34d1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit c7d34d1

Please sign in to comment.