dotnet / roslyn-analyzers

MIT License
1.59k stars 466 forks source link

Public API analyzer ignores compiler-generated methods #5826

Open bash opened 2 years ago

bash commented 2 years ago

Analyzer

Diagnostic ID: RS0016

Analyzer source

NuGet Package: Microsoft.CodeAnalysis.PublicApiAnalyzers

Version: 3.3.3 (Latest)

Describe the bug

Methods generated by the compiler for records generate no warning when not listed in PublicAPI.(Un)shipped.txt. Adding the members by hand causes the analyzer to generate a RS0017 warning.

Steps To Reproduce

  1. Define a record (with or without a primary constructor):
    public record Person(string Name);
  2. Apply the code fix for all RS0016 warnings.

Expected behavior

PublicAPI.Unshipped.txt should include public compiler-generated methods, such as ToString(), Equals(), Deconstruct(), ==, etc.

Actual behavior

PublicAPI.Unshipped.txt only contains the type, constructor and property accessors.

bitbonk commented 2 years ago

Alternatively (preferably?) PublicAPI.(Un)shipped.txt could/should denote that Person is a record.