-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
The policy around adding a virtual keyword was decided back in dotnet/runtime#21750. While this may technically be a breaking change, this method of making a method virtual has been used in the past in a backwards-compatible way. C# users in particular have treated adding a virtual keyword as a legal API change.
Interface members are dynamically dispatched, regardless of whether the virtual keyword is present. However, the dispatch for a sealed interface method can be call, although the C# compiler generates callvirt.
Even if the dispatch is always the same, this could potentially be a breaking change if an interface member is changed from sealed to virtual or vice-versa. For example:
using System;
B b = new C();
b.F(); // prints "B" if sealed, "C" otherwise
interface B {
public sealed void F() {
Console.WriteLine("B");
}
}
public class C: B {
public void F() {
Console.WriteLine("C");
}
}Perhaps API compatibility checkers should introduce the above checks when an additional flag is passed? Strict mode is already taken to mean bidirectional checking, so maybe a Full flag to indicate that all of the rules are verified?