Skip to content

Commit

Permalink
Merge pull request #1097 from AArnott/fixFeedbackTicket1645072
Browse files Browse the repository at this point in the history
Fix VSTHRD110 failure to handle unobserved tasks in finalizers
  • Loading branch information
AArnott committed Oct 21, 2022
2 parents d575259 + 0f0921d commit 0a1c1b1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ internal static ContainingFunctionData GetContainingFunction(CSharpSyntaxNode sy
BlockSyntax block => o.WithBody(block),
_ => throw new NotSupportedException(),
},
DestructorDeclarationSyntax d => (CSharpSyntaxNode newBody) => newBody switch
{
ArrowExpressionClauseSyntax expr => d.WithExpressionBody(expr),
BlockSyntax block => d.WithBody(block),
_ => throw new NotSupportedException(),
},
_ => throw new NotSupportedException(),
};
return new ContainingFunctionData(method, method.Modifiers.Any(SyntaxKind.AsyncKeyword), method.ParameterList, method.Body, bodyReplacement);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,30 @@ async Task Foo(Test? tester)
await Verify.VerifyAnalyzerAsync(test);
}

[Fact]
public async Task TaskInFinalizer()
{
string test = @"
using System;
using System.Threading.Tasks;
public class Test : IAsyncDisposable
{
~Test()
{
Task.[|Run|](async () => await DisposeAsync().ConfigureAwait(false));
}
public async ValueTask DisposeAsync()
{
await Task.Delay(5000);
}
}
";

await Verify.VerifyAnalyzerAsync(test);
}

private DiagnosticResult CreateDiagnostic(int line, int column, int length)
=> Verify.Diagnostic().WithSpan(line, column, line, column + length);
}
Expand Down

0 comments on commit 0a1c1b1

Please sign in to comment.