-
Notifications
You must be signed in to change notification settings - Fork 128
Open
Labels
Milestone
Description
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.
sbomer