-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Avoid producing Requires* warnings when accessing constant fields #84622
Conversation
Fields can only be annotated with `Requires*` attributes through their type (so RUC on type and so on). But that annotation is actually not guarding access to the field itself, but it's actually guarding access to static members, including static constructor. Constant fields don't trigger static constructor. In fact at runtime constant fields are never accessed by code. The compiler is required to inline their values instead. So IL based scanners will never produce the above warning, only analyzer would. This change modifies the analyzer to stop producing warings for accessing constant fields. Fixes dotnet#84433
Tagging subscribers to this area: @agocke, @sbomer, @vitek-karas Issue DetailsFields can only be annotated with Constant fields don't trigger static constructor. In fact at runtime constant fields are never accessed by code. The compiler is required to inline their values instead. So IL based scanners will never produce the above warning, only analyzer would. This change modifies the analyzer to stop producing warings for accessing constant fields. Fixes #84433
|
Tagging subscribers to 'linkable-framework': @eerhardt, @vitek-karas, @LakshanF, @sbomer, @joperezr, @marek-safar Issue DetailsFields can only be annotated with Constant fields don't trigger static constructor. In fact at runtime constant fields are never accessed by code. The compiler is required to inline their values instead. So IL based scanners will never produce the above warning, only analyzer would. This change modifies the analyzer to stop producing warings for accessing constant fields. Fixes #84433
|
|
|
@vitek-karas the wasm failures are unrelated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @vitek-karas!
Fields can only be annotated with
Requires*
attributes through their type (so RUC on type and so on). But that annotation is actually not guarding access to the field itself, but it's actually guarding access to static members, including static constructor.Constant fields don't trigger static constructor. In fact at runtime constant fields are never accessed by code. The compiler is required to inline their values instead.
So IL based scanners will never produce the above warning, only analyzer would.
This change modifies the analyzer to stop producing warings for accessing constant fields.
Fixes #84433