Skip to content

Commit c7d34d1

Browse files
authored
Merge pull request #1385 from microsoft/fix1363
Fix VSTHRD110 false negative in local functions of async methods
2 parents f8b0a4f + 50873c3 commit c7d34d1

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/Microsoft.VisualStudio.Threading.Analyzers/CommonInterest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ public static bool IsAwaitable(this ITypeSymbol? typeSymbol, SemanticModel seman
279279
{
280280
while (operation?.Parent is not null)
281281
{
282-
if (operation.Parent is IAnonymousFunctionOperation or IMethodBodyOperation)
282+
if (operation.Parent is IAnonymousFunctionOperation or IMethodBodyOperation or ILocalFunctionOperation)
283283
{
284284
return operation.Parent;
285285
}

test/Microsoft.VisualStudio.Threading.Analyzers.Tests/VSTHRD110ObserveResultOfAsyncCallsAnalyzerTests.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,4 +485,34 @@ class Class1
485485

486486
await CSVerify.VerifyAnalyzerAsync(test);
487487
}
488+
489+
[Fact]
490+
public async Task LocalVoidFunctionWithinAsyncTaskMethod()
491+
{
492+
string test = /* lang=c#-test */ """
493+
using System.Threading.Tasks;
494+
495+
class Test
496+
{
497+
async Task DoOperationAsync()
498+
{
499+
DoOperationInner();
500+
501+
void DoOperationInner()
502+
{
503+
[|HelperAsync()|];
504+
}
505+
}
506+
507+
void DoOperation()
508+
{
509+
[|HelperAsync()|];
510+
}
511+
512+
Task HelperAsync() => Task.CompletedTask;
513+
}
514+
""";
515+
516+
await CSVerify.VerifyAnalyzerAsync(test);
517+
}
488518
}

0 commit comments

Comments
 (0)