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.

[feature/dataflow] Add validation that dataflow annotations match for virtuals #1028

Closed

Description

@MichalStrehovsky

Need to make sure that e.g. if an interface method has an annotated parameter, all the implementations have a matching annotation. And vice versa.

#1024 (comment)

Activity

  1. added this to the .NET5.0 milestone on Mar 26, 2020
  2. marek-safar commented on Jun 15, 2020

    @marek-safar
    Contributor

    I guess this applies to implicit interface implementations only

  3. MichalStrehovsky commented on Jun 15, 2020

    @MichalStrehovsky
    MemberAuthor

    It doesn't matter whether it's explicit or implicit. If this is restricted to implicit only, we wouldn't warn for A, but the problem is the same (at the callsite, we don't know we need to preserve the default ctor of X/Y, but the implementation assumes that it was kept (and the CreateInstance is safe).

    interface IFoo
    {
        void A(Type t);
        void B(Type t);
    }
    
    class Foo : IFoo
    {
        void IFoo.A([DynamicallyAccessed(Constructors)]Type t) => Activator.CreateInstance(t);
        public void B([DynamicallyAccessed(Constructors)]Type t) => Activator.CreateInstance(t);
    
        static void Main()
        {
            IFoo p = new Foo();
            p.A(typeof(X));
            p.B(typeof(Y));
        }
    }
  4. marek-safar commented on Jun 15, 2020

    @marek-safar
    Contributor

    I thought you were describing case like

    interface IFoo
    {
        void A([DynamicallyAccessed(Constructors)]Type t);
    }

    Do we have any data which shows this can be actually implemented for at least some real-world cases (putting generics problem aside) ?

  5. MichalStrehovsky commented on Jun 15, 2020

    @MichalStrehovsky
    MemberAuthor

    If the interface is annotated but the implementation isn't, this is less of a problem - it's only weakening the annotation (we ensured linker keeps more stuff than the particular implementation needs - there still might be a different implementation that needs what the interface demands).

    This is needed to achieve correctness so I didn't look whether there is real world code using the pattern - if we don't fix this, we could see linker breaking an app without generating a warning about it.

  6. marek-safar commented on Jun 15, 2020

    @marek-safar
    Contributor

    if we don't fix this, we could see linker breaking an app without generating a warning about it.

    Agree but that essentially means if someone adds DynamicallyAccessed to one of the interface implementations every interface usage has to be annotated as well (kind of scary to think about it for stuff like IEnumerable)

  7. vitek-karas commented on Jul 8, 2020

    @vitek-karas
    Member

    Implemented in #1315.

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions