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

False-positive for VSTHRD110 when an incompatible GetAwaiter extension method is available #1158

Open
meziantou opened this issue Feb 25, 2023 · 1 comment

Comments

@meziantou
Copy link

meziantou commented Feb 25, 2023

Bug description

VSTHRD110 detects a GetAwaiter method is available from an extension method. However, the GetAwaiter method is not compatible with the actual result, so the code cannot be fixed.

TaskAwaiter<(T1, T2)> GetAwaiter<T1, T2>(this (Task<T1>, Task<T2>) tasks) is not compatible with (int,int).

Repro steps

  • dotnet new console
  • dotnet add package Microsoft.VisualStudio.Threading.Analyzers --version 17.5.22
  • Replace the Program.cs with the following content
using System.Runtime.CompilerServices;

var stack = new Stack<(int, int)>();
stack.Pop(); // <-- VSTHRD110, but the result (int,int) cannot be awaited.

internal static class Extensions
{

    public static TaskAwaiter<(T1, T2)> GetAwaiter<T1, T2>(this (Task<T1>, Task<T2>) tasks)
    {
        throw new NotImplementedException();
    }
}
  • dotnet build
  • => Program.cs(4,1): warning VSTHRD110: Observe the awaitable result of this method call by awaiting it, assigning to a variable, or passing it to another method

Expected behavior

No diagnostic as there is no compatible GetAwaiter method to use await.

Actual behavior

VSTHRD110 is reported

Additional context

dotnet --info

.NET SDK:
 Version:   7.0.200
 Commit:    534117727b

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.22623
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\7.0.200\

Host:
  Version:      7.0.3
  Architecture: x64
  Commit:       0a2bda10e8

.NET SDKs installed:
  7.0.103 [C:\Program Files\dotnet\sdk]
  7.0.200 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 6.0.14 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 6.0.14 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 6.0.14 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 7.0.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
  x86   [C:\Program Files (x86)\dotnet]
    registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
  Not set

global.json file:
  Not found
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants