Skip to content

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

Open
@natalie-o-perret

Description

@natalie-o-perret

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:

type Mother() =
    member this.Hello() =
        Unchecked.defaultof<int32>

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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-Compiler-SRTPbugs in SRTP inference, resolution, witness passing, code genBugImpact-Low(Internal MS Team use only) Describes an issue with limited impact on existing code.

    Type

    Projects

    Status

    New

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions