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

RUC analyzer does not warn about delegate conversion #1912

Closed
agocke opened this issue Mar 23, 2021 · 4 comments
Closed

RUC analyzer does not warn about delegate conversion #1912

agocke opened this issue Mar 23, 2021 · 4 comments
Assignees

Comments

@agocke
Copy link
Member

agocke commented Mar 23, 2021

E.g.

[RequiresUnreferencedCode("")]
void M1() { }
void M2()
{
    Action a = M1; // should warn
    Action b = () => M1(); // should warn
}
@MichalStrehovsky
Copy link
Member

Dupe of #1764? "We should probably extend this to delegates pointing to such methods (although that one has a natural extension - we could require the delegate invoke method itself to be annotated same as the target)."

@agocke
Copy link
Member Author

agocke commented Mar 23, 2021

Yeah, they're maybe dups -- this bug was specific to the analyzer, but if the linker is missing similar analysis it makes sense to do both together.

My suggestion is simpler as well-- warn at the point of delegate conversion, instead of Invoke, so we don't have to do alias tracking for delegate instances. From what I've seen it's often not a worse experience anyway because users often want to see the origination of the problem instead of the final invocation.

@MichalStrehovsky
Copy link
Member

My suggestion is simpler as well-- warn at the point of delegate conversion, instead of Invoke

Yup, this is also what I want linker to do. The comment about invoke method is just that we could potentially allow delegate conversion if the delegate itself has matching annotations. So for example:

delegate ConstructorInfo GimmeConstructor([DynamicallyAccessedMembers(Constructors)] Type theType);

Could be used to construct a delegate pointing to an annotated method. The annotations at the delegate use site naturally fall out.

Unfortunately, it doesn't look like C# allows placing attributes on the Invoke method itself, so the natural extension for RequiresUnreferencedCode doesn't look possible. But it could work at least for the flow annotations if we have the need.

@tlakollo
Copy link
Contributor

tlakollo commented Jul 1, 2021

While reviewing the tests and adding some more for RAF I realized that both Linker and Analyzer already have support for this so I will close this PR and add lazy tests in #2113

@tlakollo tlakollo closed this as completed Jul 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants