Skip to content

VSTHRD100 (avoid async void) doesn't work for local functions #1074

Description

Bug description

VSTHRD100 fires for async void methods, but not for local functions.

Repro steps

class C
{
    async void M() // VSTHRD100 
    {
        async void L() {} // no diagnostic
    }
}

Expected behavior

VSTHRD100 should fire on local function L in the above example.

Actual behavior

VSTHRD100 does not fire on local function L in the above example.

  • Version used: 17.3.22-alpha
  • Application (if applicable): dotnet/project-system

Activity

  1. drewnoakes commented on Jul 25, 2022

    @drewnoakes
    MemberAuthor

    This library is using a relatively old version of Microsoft.CodeAnalysis.Common (2.10.0) which doesn't appear to support local functions.

    Bumping to the latest version (4.2.0) requires increasing the target framework from netstandard1.3 to netstandard2.0.

    Any concerns with that?

  2. drewnoakes commented on Jul 25, 2022

    @drewnoakes
    MemberAuthor

    This diagnostic should also fire for async void lambdas.

  3. AArnott commented on Jul 25, 2022

    @AArnott
    Member

    I have no concern about bumping the target framework. But jumping to 4.2.0 in the package references means that the vs-threading analyzers won't support older VS versions, correct? Do we have a table mapping compiler versions to VS versions so we know what we're leaving behind?

  4. drewnoakes commented on Jul 25, 2022

    @drewnoakes
    MemberAuthor

    I ended up not needing to bump those levels in the PR, but forgot to update this issue.

  5. AArnott commented on Jul 26, 2022

    @AArnott
    Member

    #1075 regressed VSTHRD100 because now it fires on lambdas, which is the purview of VSTHRD101. As a result, we had an insertion blockage due to new warnings that were all redundant with VSTHRD101 anyway.

    This issue was about identifying local functions, but the PR to address that added lambda detection as well, which I should have noticed since that was in the PR title and in fact was the only thing the new tests covered rather than covering the local function scenario.

  6. added this to the v17.4 milestone on Jul 26, 2022
  7. AArnott commented on Jul 26, 2022

    @AArnott
    Member

    Drew Noakes (@drewnoakes) would you like to take another try at this issue, including rolling back the lambda detection? This is blocking vs-threading insertions so we need to address this right away. If you're not available I'll give it a quick try but just for expediency, we might roll back the original PR till we can fix this issue in a better way.

  8. drewnoakes commented on Jul 28, 2022

    @drewnoakes
    MemberAuthor

    Seems like #1076 should cover it.

  9. AArnott commented on Jul 28, 2022

    @AArnott
    Member

    Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions