dotnet / dotnet/fsharp

Return types in shadowing members are not considered in generic constraint resolution to avoid ambiguity.

Open
#8,794 4 comments 1 reaction 0 assignees View on GitHub
Area-Compiler-SRTP Bug Impact-Low
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 11h
Merged PRs (30d)
131

Description

**Description**

It seems that when a member is shadowing an inherited member with a different return type, the return type is not considered to avoid any ambiguity when the compiler is attempting to resolve the member.

**Repro steps**

Self-explanatory example:
```fsharp
type Mother() =
member this.Hello() =
Unchecked.defaultof

type Daughter() =
inherit Mother()
member this.Hello() =
Unchecked.defaultof

type SomeoneHolder<'Someone when 'Someone: (member Hello : unit -> string)> =
{ Someone: 'Someone }

let someoneHolder =
{ Someone = Daughter() }
```

**Expected behavior**

It should compile.

**Actual behavior**

It does not, with the error below:

> [FS0001] A unique overload for method 'Hello' could not be determined based on type information prior to this program point.
> A type annotation may be needed. Candidates: `member Daughter.Hello : unit -> string`, `member Mother.Hello : unit -> int32`

**Known workarounds**

None.

**Related information**

Provide any related information (optional):

The return type

* Operating system: Windows 10 Enterprise
* .NET Runtime kind (.NET Core, .NET Framework, Mono): .NET Core 3.1
* Editing Tools (e.g. Visual Studio Version, Visual Studio): Rider

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.