dotnet / roslyn-analyzers

MIT License
1.59k stars 466 forks source link

No RS0016/RS0017 warnings when a public member was made protected #5768

Open bitbonk opened 2 years ago

bitbonk commented 2 years ago

Analyzer

Diagnostic ID: RS0016: Add public types and members to the declared API and/or RS0017 Remove deleted types and members from the declared API

Analyzer source

NuGet Package: Microsoft.CodeAnalysis.PublicApiAnalyzers

Version: 3.3.3 (Latest)

Describe the bug

The analyzers do not detect changes when a once public member of a public class was changed to a protected member in the same class.

Steps To Reproduce

  1. Change public member of a public class to to a protected member in the same class inside a project that already uses Microsoft.CodeAnalysis.PublicApiAnalyzers.

Expected behavior

I get an analzer warning warning (RS0016 and RS0017) that the API is missing.

Actual behavior

No warnings happen.

Additional context

In our concrete case, we had this in PublicAPI.Shipped.txt Some.Namespace.BootstrapperBase.Initialize() -> void

After we changed Initialize() from public to protected in the .cs file no analyzers were summoned.

It looks like the public/protected access modifiers are not part of the text files and are generally ignored but changing them will cause breaking changes too. I would think that protecting us from breaking changes in the public API is the whole idea behind Microsoft.CodeAnalysis.PublicApiAnalyzers.

Youssef1313 commented 2 years ago

https://github.com/dotnet/roslyn-analyzers/pull/4992 should be fixing this. I'll try to get it completed and merged soon.

bitbonk commented 1 year ago

@Youssef1313 Any update on this? I tested this in 3.3.4 and the problem is still present (this time a constructor was made protected without a warning).