Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

APICompat attribute handling inaccurate #35542

Open
ericstj opened this issue Sep 19, 2023 · 3 comments
Open

APICompat attribute handling inaccurate #35542

ericstj opened this issue Sep 19, 2023 · 3 comments

Comments

@ericstj
Copy link
Member

ericstj commented Sep 19, 2023

Attributes don't participate in binding and binary compatibility in the same way as types/members. Attributes are consumed by other tools and runtime technology and interpreted differently on a case-by-case basis.

APICompat is ignorant of this and tries to help by just asserting that attributes should remain and be unchanged. In some cases this is helpful, but in a lot of cases it create noise and degrades the experience when working with APICompat.

We were aware of this when adding the AttributesMustMatch rule, which is why it's opt-in and configurable with a list of attributes, but we never tracked improving this.

I think that for many attributes we can promote them to non-optional rules and make them on-by-default. Examples are AttributeUsage, StructLayout, TypeConverter, SupportedOSPlatform, Obsolete. When promoting an attribute to have a special-purpose rule we should omit it from the AttributesMustMatch rule.

Other things to consider when addressing this -- should we introduce more information in the AttributesMustMatch diagnostics to make suppressions more targetable, or is a list of attribute exclusions good enough? Ensure we consider the differences in strict vs compatible comparisons -- these seem straightforward for all the cases mentioned above.

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-ApiCompat untriaged Request triage from a team member labels Sep 19, 2023
@ghost
Copy link

ghost commented Sep 19, 2023

@dotnet/area-infrastructure-libraries a new issue has been filed in the ApiCompat area, please triage

@ericstj ericstj added this to the 9.0.1xx milestone Sep 19, 2023
@ericstj
Copy link
Member Author

ericstj commented Sep 22, 2023

#18681 tracks the fix for better handling of all nullable attributes.

@bitbonk
Copy link

bitbonk commented Jan 15, 2025

@ericstj

Attributes don't participate in binding and binary compatibility

Just to be clear about the purpose of the ApiCompat tooling. It exists not only to detect binary incompatibilities but also source incompatibilities, right? For example, adding the ObsoleteAttribute to a public method is binary compatible but not source compatible because it would result in a new compiler warning when consuming code is recompiled. Adding a new value to a public enum is another example: #45929

Library authors also need to be careful about source incompatibilities and the tooling should help them with that.

@ViktorHofer ViktorHofer removed the untriaged Request triage from a team member label Mar 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants