Skip to content
This repository was archived by the owner on Sep 25, 2026. It is now read-only.
This repository was archived by the owner on Sep 25, 2026. It is now read-only.

RUC analyzer does not warn about delegate conversion #1912

Closed

Description

@agocke

E.g.

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

Activity

  1. MichalStrehovsky commented on Mar 23, 2021

    @MichalStrehovsky
    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)."

  2. agocke commented on Mar 23, 2021

    @agocke
    MemberAuthor

    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.

  3. MichalStrehovsky commented on Mar 23, 2021

    @MichalStrehovsky
    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.

  4. tlakollo commented on Jul 1, 2021

    @tlakollo
    Contributor

    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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions