You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the following code public void M(object arg) should be enough to implement the interface but neither the compiler nor the runtime accept such code and an explicit impl is required to bridge the two overloads. (sharplab.io)
interfaceISomeInterface<inT>{voidM(Targ);}interfaceIBase:ISomeInterface<object>;interface IDerived :IBase,ISomeInterface<string>{// uncomment to resolve the error but this shouldn't be necessary// void ISomeInterface<string>.M(string obj) => M(obj as object); // calls base}classC:IDerived{// error: method `M(string)` is not implementedpublicvoidM(objectarg){}}
The text was updated successfully, but these errors were encountered:
i thnik this would take a language change. i don't think the variance part of the lang spec supports this. The variance part affects things like conversions, but not interface impls.
Indeed, but since identical method signatures from different interfaces are already merged, I think this would be just a relaxation of that rule in both sides. On the runtime, the variance already guaranteed that the call is safe.
In the following code
public void M(object arg)
should be enough to implement the interface but neither the compiler nor the runtime accept such code and an explicit impl is required to bridge the two overloads. (sharplab.io)The text was updated successfully, but these errors were encountered: