Skip to content

Fix virtual/interface method resolution #1187

@MichalStrehovsky

Description

@MichalStrehovsky

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions