dotnet / dotnet/sdk

APICompat doesn't catch when a member changes static

Open
#52,111 1 comment 2 reactions 1 assignee Assigned to @Copilot View on GitHub
Area-ApiCompat untriaged
Dominant language
C#
Stars
3.2k
Forks
1.3k
PR merge metrics
PR metrics pending

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
```xml


net8.0;net10.0
true
enable
enable
true

```

Class1.cs
```c#
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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.