You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Sep 25, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Sep 25, 2026. It is now read-only.
Analyzer: RUC/RDC on type triggers override mismatch warnings #2763
Suppress trim analysis warnings in all method bodies
But the analyzer in this case treats it as if it has RUC on virtual methods as well.
The IL2046 is expected if the derived method as RUC on it, but the class as a whole should not trigger this warning since it doesn't imply any changes to instance methods as seen from outside (calling instance methods on RUC annotated type does not produce warnings, only .ctors do).
Base has the attribute in the method directly, which means that it will look to have the same annotation in the Derived. Derived uses a type annotation but doesn't cover the method because is not static. Is this something we want?
I would think that the example you gave @tlakollo would not produce any warnings - effectively, RUC on type does mean that the virtual methods are "unsafe" to execute, but we just don't warn for calls to them, because we are blaming the constructor instead. Similarly in the original issue, there is effectively a mismatch, but there's no way to execute the override without calling the constructor, so blaming it means we don't need to produce warnings about the "mismatch".
I think the two scenarios collide with each other. The question to be answered is: Is the method in the derived class in the Requires scope? In the first scenario, we want to answer no because the method is not static. In the second example, the answer should be the same, the difference being that Base is in the Requires Scope which should create a mismatch warning.
I realize it's implemented that way currently, but I think we need to add some logic that checks for RUC on type. If the derived class has RUC on the type it shouldn't produce this warning. I think the same is probably true of the base type - since we already produce a warning at the type level.
A method can create a "RUC" requirement - that is "I the method am dangerous, anybody who can call me needs to warn"
A method can fulfill a "RUC" requirement - that is "You can't get to me without triggering a warning"
The creation of RUC requirement is:
Method which has a RUC on it creates a requirement
Static method on a RUC annotated type creates a requirement
.ctor on a RUC annotated type creates a requirement
The fulfillment of RUC requirement is:
Method which has a RUC on it fulfills a requirement
Any method on a RUC annotated type fulfills requirement
Notice the different, only static/.ctor methods on RUC types create requirements, but all methods on RUC types fulfill them.
So for the override it means - only a method with RUC directly on it creates a requirement and needs to check that its base/overrides fulfill the requirement.
(We will have to think carefully about static abstract methods on interfaces - as those are static but also virtual... so weird - but that's and edge case for now).
Reacted by Sven Boemer
Reacted by Tlakaelel Axayakatl Ceja and Lakshan Fernando
Activity
Add a test for RUC on type with override method
vitek-karas commentedon Apr 26, 2022
PR #2764 adds a test for this case.
vitek-karas commentedon Apr 26, 2022
/cc @LakshanF
Add a test for RUC on type with override method (#2764)
tlakollo commentedon Apr 26, 2022
What about the following:
Base has the attribute in the method directly, which means that it will look to have the same annotation in the Derived. Derived uses a type annotation but doesn't cover the method because is not static. Is this something we want?
sbomer commentedon Apr 26, 2022
I would think that the example you gave @tlakollo would not produce any warnings - effectively, RUC on type does mean that the virtual methods are "unsafe" to execute, but we just don't warn for calls to them, because we are blaming the constructor instead. Similarly in the original issue, there is effectively a mismatch, but there's no way to execute the override without calling the constructor, so blaming it means we don't need to produce warnings about the "mismatch".
tlakollo commentedon Apr 26, 2022
I think the two scenarios collide with each other. The question to be answered is: Is the method in the derived class in the Requires scope? In the first scenario, we want to answer no because the method is not static. In the second example, the answer should be the same, the difference being that Base is in the Requires Scope which should create a mismatch warning.
sbomer commentedon Apr 26, 2022
I realize it's implemented that way currently, but I think we need to add some logic that checks for RUC on type. If the derived class has RUC on the type it shouldn't produce this warning. I think the same is probably true of the base type - since we already produce a warning at the type level.
vitek-karas commentedon Apr 26, 2022
I think the logic is split:
The creation of RUC requirement is:
The fulfillment of RUC requirement is:
Notice the different, only static/.ctor methods on RUC types create requirements, but all methods on RUC types fulfill them.
So for the override it means - only a method with RUC directly on it creates a requirement and needs to check that its base/overrides fulfill the requirement.
(We will have to think carefully about static abstract methods on interfaces - as those are static but also virtual... so weird - but that's and edge case for now).
Change requires on type checking for mismatch (#2766)
Add a test for RUC on type with override method (dotnet/linker#2764)
Change requires on type checking for mismatch (dotnet/linker#2766)