Skip to content

F# 5.0 Regression with generic overloads containing nullable #10547

@jbtule

Description

@jbtule

There appears to be an issue with type inference and generic overloads that doesn't exist in 4.7, causing the same code not to compile with 5.0.

Repro steps

Provide the steps required to reproduce the problem:

  1. Step A
type OverloadMeths =
    static member Map(m: 'T option, f) = Option.map f m
    static member Map(m: 'T when 'T:null, f) = m |> Option.ofObj |> Option.map f
    //works in 5.0 if you comment out this line
    static member Map(m: 'T Nullable, f) = m |> Option.ofNullable |> Option.map f

[<AllowNullLiteral>]
type Node (child:Node)=
    new() = new Node(null)
    member val child:Node = child with get,set
  1. Step B
let parent = Node()
let b1 = OverloadMeths.Map(parent.child, fun x -> x.child)  //compiler error on this line in F# 5,0
let c1 = OverloadMeths.Map(b1, fun x -> x.child)

Git repo of example with an F# 4.7 and 5.0 project in Visual Studio Solution: https://github.com/jbtule/Fsharp5OverloadIssue

Expected behavior

Compile without error

Actual behavior

Compiler error
Error FS0072 Lookup on object of indeterminate type based on information prior to this program point. A type annotation may be needed prior to this program point to constrain the type of the object. This may allow the lookup to be resolved.

Known workarounds

<LangVersion>4.7</LangVersion>

Related information

Provide any related information (optional):

  • F# 5.0
  • .net 5.0
  • Visual Studio Version 16.8.2

Metadata

Metadata

Assignees

Labels

Impact-High(Internal MS Team use only) Describes an issue with extreme impact on existing code.Regression

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions