Skip to content

Unexpected type inference for Run method - generic constraints are checked too late #19349

@Lanayx

Description

@Lanayx

Repro steps

open System.Runtime.CompilerServices

// -------------------------
// "View engine" bits
// -------------------------
type HtmlContainer() = class end

type HtmlContainerFun = HtmlContainer -> unit

[<Extension>]
type HtmlContainerExtensions =
    [<Extension>]
    static member inline Run(this: #HtmlContainer, [<InlineIfLambda>] runExpr: HtmlContainerFun) =
        runExpr this
        this

// -------------------------
// "AsyncSeq-like" CE builder bits
// -------------------------
type AsyncSeq<'T> = private AsyncSeq of 'T list

type AsyncSeqBuilder() =
    member _.Yield(x: 'T) : AsyncSeq<'T> =
        AsyncSeq [x]

let asyncSeq = AsyncSeqBuilder()

let xs : AsyncSeq<int> =
    asyncSeq {
        yield 1
    }

From Don's comment:

This could be onsidered an F# compiler bug but we'd have to check the spec - the compiler commits to using this Run before it knows the constraint check #HtmlContainer will fail.

Expected behavior

Code compiles just fine - Run method from HtmlContainerExtensions isn't used for asyncSeq

Actual behavior

error FS0193: The type 'AsyncSeqBuilder' is not compatible with the type 'HtmlContainer'

Known workarounds

No workarounds are known

Related information

Related issues:
Lanayx/Oxpecker#93
fsprojects/FSharp.Control.AsyncSeq#239

.NET SDK 10.0.102

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    Status

    New

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions