Making a member virtual should be considered a breaking change #21750
Labels
area-Meta
documentation
Documentation bug or enhancement, does not impact product or test code
help wanted
[up-for-grabs] Good issue for external contributors
Milestone
The breaking change document currently considers making a member virtual a non-breaking change with a small sidenote. When that rule was decided, the C# compiler was only emitting
call
IL instruction in a couple places that didn't really matter and used the ILcallvirt
for everything else (even if the destination instance method was non-virtual, because per the C# spec, calling instance methods with a nullthis
needs to throw andcall
IL instruction won't throw). This made it unlikely that people would hit problems with it.The addition of the null-propagation operator gave the C# compiler more opportunities to optimize
callvirt
into acall
if thethis
is known to be not null.dotnet/corert#3565 has an example where making a member virtual resulted in wrong method being called when compiling against PCL contracts because a breaking change was made making
ConstructorInfo.Invoke
virtual:Making a member virtual is a breaking change for anyone using the null-propagation operator with the method.
The text was updated successfully, but these errors were encountered: