Issue subclassing type with covariant return override of abstract base member
C# 9 introduced the ability to override a virtual base member with a covariant return type. For instance, if a virtual method in Class1 returns object, then an override of that method in a derived Class2 can return string.
Generally, it seems F# has no issue instantiating and using Class1 or Class2 and calling the overridden method. However, if the method in Class1 is abstract and you try to create a Class3 in F# that derives from Class2, the compiler doesn't recognize that Class2 overrides the abstract member from Class1 and insists that you need to do it in Class3 (or mark it abstract).
Repro steps
- Clone https://github.com/chkn/CovariantReturnTypeBug
- Go to the FSharp folder
-
dotnet build
Expected behavior
It should compile successfully.
Actual behavior
.../CovariantReturnType/FSharp/Program.fs(3,6): error FS0365: No implementation was given for 'Class1.Foo() : obj' [.../CovariantReturnType/FSharp/FSharp.fsproj]
.../CovariantReturnType/FSharp/Program.fs(3,6): error FS0054: This type is 'abstract' since some abstract members have not been given an implementation. If this is intentional then add the '[<AbstractClass>]' attribute to your type. [.../CovariantReturnType/FSharp/FSharp.fsproj]
Known workarounds
???
Related information
Provide any related information (optional):
- Operating system: macOS
- .NET Runtime: .NET 6
- Editing Tools (e.g. Visual Studio Version, Visual Studio)
@KathleenDollard @vzarytovskii This comes under the general bucket of "need to do work to modernize C# interop"