DotNetAnalyzers / StyleCopAnalyzers

An implementation of StyleCop rules using the .NET Compiler Platform
MIT License
2.65k stars 508 forks source link

CA2000 Erroneous warnings for IAsyncDisposable #3889

Closed symbiogenesis closed 2 weeks ago

symbiogenesis commented 2 weeks ago

Consider the following examples:

await using var asyncDisposable = new AsyncDisposable();

Foo();

This should never throw CA2000, but I see it.

Consider, also:

var asyncDisposable = new AsyncDisposable();

await using (asyncDisposable.ConfigureAwait(false))
{
    Foo();
}

I would not expect this to result in a warning as long as asyncDisposable is not accessed again outside of the await using block.

Note: In the event of ConfigureAwait() being applied, the disposable becomes type ConfiguredAsyncDisposable

bjornhellander commented 2 weeks ago

CAxxxx diagnostics are triggered by a package built from this repo: https://github.com/dotnet/roslyn-analyzers

symbiogenesis commented 2 weeks ago

Ah, thanks!