Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VSTHRD110 does not trigger when using null-conditional member access #772

Closed
AlexVallat opened this issue Feb 16, 2021 · 1 comment · Fixed by #867
Closed

VSTHRD110 does not trigger when using null-conditional member access #772

AlexVallat opened this issue Feb 16, 2021 · 1 comment · Fixed by #867

Comments

@AlexVallat
Copy link

Bug description

If the async method is called using null-conditional member access, no warning (neither VSTHRD110 nor CS4014) is raised.

Repro steps

class Example
{
    void Foo(Example mayNotBeNull, Example? mayBeNull)
    {
        DoStuffAsync();
        mayNotBeNull.DoStuffAsync();
        mayBeNull?.DoStuffAsync();
    }
    async Task DoStuffAsync() { /* ... */ }
}

Expected behavior

VSTHRD110 raised on all three lines in Foo method

Actual behavior

VSTHRD110 raised on first two lines in Foo method only, not on mayBeNull?.DoStuffAsync()

  • Version used: 16.8.55
  • Application (if applicable): Visual Studio 16.8.5
@AArnott
Copy link
Member

AArnott commented Feb 16, 2021

As a note when this is addressed: the fix is not simply to add an await. The existing syntax would have to properly handle the null case in order to avoid a NRE:

await (mayBeNull?.DoStuffAsync() ?? Task.CompletedTask);

bluetarpmedia added a commit to bluetarpmedia/vs-threading that referenced this issue Jun 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants