tunnelvisionlabs / ReferenceAssemblyAnnotator

IL weaver to add nullability annotations to .NET reference assemblies
MIT License
72 stars 8 forks source link

SocketAsyncEventArgs.Completed event nullability is incorrectly written #93

Open jnm2 opened 1 year ago

jnm2 commented 1 year ago

ReferenceAssemblyAnnotator creates SocketAsyncEventArgs.Completed with a bizarre nullable event args parameter:

image

No diagnostic should be shown here. When compiling on net6.0, there is no diagnostic for this sample code.

I decompiled %userprofile\.nuget\packages\microsoft.netcore.app.ref\6.0.0\ref\net6.0\System.Net.Sockets.dll and confirmed that it has public event EventHandler<SocketAsyncEventArgs>? Completed;, not public event EventHandler<SocketAsyncEventArgs?>? Completed;.

Repro

using System.Net.Sockets;

var x = new SocketAsyncEventArgs();

// ⚠️ CS8622 Nullability of reference types in type of parameter 'e' of 'void OnCompleted(object? sender,
// SocketAsyncEventArgs e)' doesn't match the target delegate 'EventHandler<SocketAsyncEventArgs?>' (possibly
// because of nullability attributes).
//             ↓↓↓↓↓↓↓↓↓↓↓
x.Completed += OnCompleted;

void OnCompleted(object? sender, SocketAsyncEventArgs e)
{
}
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net48</TargetFramework>
    <Nullable>enable</Nullable>
    <LangVersion>11</LangVersion>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="TunnelVisionLabs.ReferenceAssemblyAnnotator" Version="1.0.0-alpha.160" />
    <PackageDownload Include="Microsoft.NETCore.App.Ref" Version="[6.0.0]" />
  </ItemGroup>

</Project>