Skip to content

Unexpected type inference issue in CE overloads #18734

@Lanayx

Description

@Lanayx

Addition of the problematic overload breaks inference for non-related cases, see ProblematicClass overload below. What is very strange - that the issue doesn't occur with C# classes that implement at least one interface (for example the issue won't reproduce if you replace ProblematicClass with StringBuilder). Issue still persists with F# classes (interfaces don't help) or C# classes that don't implement at least one interface, which confirms that current situation is buggy.

Related issue Lanayx/Oxpecker#76

Repro steps

type IMarker = interface end

type Test() = interface IMarker

// Problematic class
type ProblematicClass() = class end

type TestFun = Test -> unit

type Test with
    member inline _.Combine
        (first: TestFun, second: TestFun)
        : TestFun =
        fun builder ->
            first builder
            second builder

    member _.Zero() : TestFun = ignore

    member _.Delay(delay: unit -> TestFun) : TestFun = delay()

    member _.Yield(element: #IMarker) : TestFun = fun cont -> ignore element

    // Problematic overload
    member _.Yield(element: ProblematicClass) : TestFun = fun cont -> ignore element

    member this.Run(runExpr: TestFun) =
        runExpr this
        this

let inner (children: #IMarker) =
    Test() {
        children
    }

let test () =
    Test() {
        inner <| Test()
    }

Expected behavior

Overload should just work

Actual behavior

The error is shown The type 'Test' is not compatible with the type 'ProblematicClass'

Known workarounds

No known workarounds.

Related information

Provide any related information (optional):

  • Windows 10
.NET SDK:
 Version:           9.0.301
 Commit:            a596cd22e2
 Workload version:  9.0.300-manifests.9bcbba73
 MSBuild version:   17.14.5+edd3bbf37
  • JetBrains Rider 2025.1.4
Image

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    Status

    New

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions