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

Fix virtual/interface method resolution #1187

Open
MichalStrehovsky opened this issue May 13, 2020 · 0 comments
Open

Fix virtual/interface method resolution #1187

MichalStrehovsky opened this issue May 13, 2020 · 0 comments

Comments

@MichalStrehovsky
Copy link
Member

The virtual method resolution algorithm in use within linker is quite wrong and very difficult to map to the spec. One doesn't even go into the IL-level corner cases to get the algorithm to do wrong things.

For example, this is going to generate invalid outputs after linking:

interface IFoo
{
    void Frob(int x);
}

class Base<T>
{
    // Linker thinks this method implements IFoo.Frob in Derived
    protected virtual void Frob(int x) => Console.WriteLine("Unrelated");
    public virtual void Frob(T x) => Console.WriteLine("Actual");
}

class Derived : Base<int>, IFoo
{
}

This is going to keep more methods than necessary:

interface IFoo
{
    void Frob();
}

class Base : IFoo
{
    // Linker thinks both methods implement the interface
    public virtual void Frob() => Console.WriteLine("NameAndSig");
    void IFoo.Frob() => Console.WriteLine("MethodImpl");
}

This will also keep more methods than necessary:

class Base
{
    protected virtual void Frob() => Console.WriteLine("Nobody calls me");
}

class Derived : Base
{
    // Linker thinks this overrides Base.Frob, but they’re unrelated
    public new virtual void Frob() => Console.WriteLine("I am used");
}

This needs to be reimplemented according to the spec.

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

2 participants