Skip to content
This repository has been archived by the owner on Nov 1, 2020. It is now read-only.

Accessibility not respected by the interface resolution algorithm #1986

Closed
MichalStrehovsky opened this issue Oct 6, 2016 · 1 comment · Fixed by dotnet/runtime#81409
Closed
Assignees
Milestone

Comments

@MichalStrehovsky
Copy link
Member

MichalStrehovsky commented Oct 6, 2016

B.f is protected and we shouldn't consider it as implementing the interface.

using System;
interface I
{
    int f();
}
class A
{
    public int f()
    {
        Console.WriteLine("Correct  ->  Should be in A.f()");
        return 100;
    }
}
class B : A, I
{
    new protected virtual int f()
    {
        Console.WriteLine("Incorrect  ->  Shouldnt be in B.f()");
        return 1;
    }
    static int Main()
    {
        B b = new B();
        I i = b;
        return i.f();
    }
}
@MichalStrehovsky
Copy link
Member Author

Cc @hoyMS

@MichalStrehovsky MichalStrehovsky added this to the March 2017 milestone Oct 20, 2016
@MichalStrehovsky MichalStrehovsky changed the title Method declaration order not respected in interface method resolution Accessibility not respected by the interface resolution algorithm Jan 18, 2018
MichalStrehovsky added a commit to MichalStrehovsky/runtime that referenced this issue Jan 31, 2023
Fixes dotnet/corert#1986 (yep, all the way to CoreRT repo).

We finally found an instance where this matters - in MAUI. Non-public methods never implement an interface by name+sig combo. We got the `ProtectedDerived` case in the newly added test wrong.
MichalStrehovsky added a commit to dotnet/runtime that referenced this issue Feb 2, 2023
Fixes dotnet/corert#1986 (yep, all the way to CoreRT repo).

We finally found an instance where this matters - in MAUI. Non-public methods never implement an interface by name+sig combo. We got the `ProtectedDerived` case in the newly added test wrong.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants