dotnet / dotnet/fsharp

Issue subclassing type with covariant return override of abstract base member

Open
#13,201 1 comment 1 reaction 1 assignee Claimed by @edgarfgp View on GitHub
Area-Compiler-Checking Area-Compiler-Checking-Overloads Bug Impact-Medium Needs-RFC
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 22h
Merged PRs (30d)
144

Description

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**

1. Clone https://github.com/chkn/CovariantReturnTypeBug
2. Go to the FSharp folder
3. `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 '[]' 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)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.