microsoft / vs-servicehub

The service broker libraries used by Visual Studio to exchange intra- and inter-process services
MIT License
21 stars 8 forks source link

ISB001 mis-fires when `GetProxyAsync` result is assigned to local in using statement #187

Closed AArnott closed 7 months ago

AArnott commented 8 months ago

This works:

using (var proxy = await isb.GetProxyAsync(...))
{
}

But this syntax leads the analyzer to mis-fire:

using var proxy = await isb.GetProxyAsync(...);
jdrobison commented 7 months ago

Also note that that even if the proxy interface derives from IDisposable, the analyzer doesn't recognize a simple using clause referring to the proxy interface as disposing the proxy.

This causes the analyzer to mis-fire:

interface IMyInterface : IDisposable { ... }

var myInterface = await isb.GetProxyAsync(...);
using (myInterface)
{
}

This does not:

interface IMyInterface : IDisposable { ... }

var myInterface = await isb.GetProxyAsync(...);
using (myInterface as IDisposable)
{
}