-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
Describe the bug
APICompat does not catch the case when a member adds or removes static
To Reproduce
Create a class library that multi-targets and add/remove static on a member.
project.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net8.0;net10.0</TargetFrameworks>
<IsPackable>true</IsPackable>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<EnablePackageValidation>true</EnablePackageValidation>
</PropertyGroup>
</Project>Class1.cs
public class Class1
{
#if NET10_0
public string Foo => "net10.0";
public static string Bar => "net10.0";
#else
public static string Foo => "net8.0";
public string Bar => "net8.0";
#endif
}Expect validation errors for both Foo and Bar since both addition and removal is binary breaking. Removing static is source breaking as well.
We should make sure we include checking for all types of API that might change by static. That should be all members.
Adding static to a type that didn't have it before can be breaking, since static types cannot be used as return types, generic parameters, arguments. We have made such changes in the past - when we had non-constructable types. We should still flag this since we cannot be sure that someone didn't decide to use that in source (even if it wasn't callable).
Removing static from a type is compatible. We'll separately evaluate all members that existed before.