Skip to content

VSTHRD110 False Negative in local functions? #1363

@PaulKlein

Description

@PaulKlein

Bug description

An async method containing a synchronous local function doesn't trigger VSTHRD110 if that local function calls unawaited task methods.

Repro steps

        async Task DoOperationAsync()
        {
            // Warning CS4014 as expected
            HelperAsync();

            DoOperationInner();

            return;

            void DoOperationInner()
            {
                // No warning, would expect VSTHRD110?
                HelperAsync();
            }
        }
        
        void DoOperation()
        {
            // Raises VSTHRD110 as expected
            HelperAsync();
        }

        Task HelperAsync()
        {
            // e.g. some helper method doing some async work
            return Task.CompletedTask;
        }

Expected behavior

A VSTHRD110 warning on the call to HelperAsync inside DoOperationInner

Actual behavior

No warning is raised

  • Version used:
    Microsoft.VisualStudio.Threading.Analyzers v17.12.19

Additional context

Thank you very much for the work you do on these analysers, they are super helpful at preventing issues in my code!
Cheers

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions