vs-threading icon indicating copy to clipboard operation
vs-threading copied to clipboard

VSTHRD110 mis-fires on null coalescing operator

Open AArnott opened this issue 4 years ago • 2 comments

Bug description

When an async method's result is returned with ?? operator, VSTHRD110 claims the result isn't returned or awaited.

Repro steps

        internal Task<T> GetClientAsync<T>(CancellationToken cancellationToken) where T : VssHttpClientBase
        {
            return _vssConnection?.GetClientAsync<T>(cancellationToken) ?? Task.FromResult<T>(null);
        }

Expected behavior

No warning.

Actual behavior

A warning.

AArnott avatar Jul 26 '21 20:07 AArnott

Duplicate of #880?

drewnoakes avatar Aug 01 '21 12:08 drewnoakes

The two issues are regarding distinct analyzers. I wouldn't know till fixing it whether there is common code behind each analyzer such that fixing one will implicitly fix the other.

AArnott avatar Aug 17 '21 17:08 AArnott

private Task ShakeTreeAsync() => Tree?.ShakeAsync() ?? Task.CompletedTask;

A simple example causing a VSTHRD110 warning where it shouldn't.

peterdrier avatar Jun 15 '23 10:06 peterdrier