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

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

Closed
MichalStrehovsky opened this issue Mar 26, 2020 · 6 comments
Assignees
Milestone

Comments

@MichalStrehovsky
Copy link
Member

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)

@marek-safar
Copy link
Contributor

I guess this applies to implicit interface implementations only

@MichalStrehovsky
Copy link
Member Author

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));
    }
}

@marek-safar
Copy link
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) ?

@MichalStrehovsky
Copy link
Member Author

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.

@marek-safar
Copy link
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)

@vitek-karas
Copy link
Member

Implemented in #1315.

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

No branches or pull requests

3 participants