Skip to content

Confusing/incorrect type mismatch message in async CE #14437

@cmeeren

Description

@cmeeren

Consider this code (type annotations added for clarity):

async {
    let asyncUnitArr : Async<unit []> = async.Return [| () |]
    do! asyncUnitArr
}

It fails to compile with this message on the second asyncUnitArr:

This expression was expected to have type 'unit[]' but here has type 'unit'

image

I find this confusing for two reasons.

Firstly, the expression that is underlined, asyncUnitArr, has the type Async<unit []>, so the message seems to be missing the Async wrapper.

Secondly, the wording/types seem to be switched around. The expression has the type Async<unit []> and (given the context) is expected to have the type Async<unit>.

For comparison, here is a similar error message that seems to be correct:

let f (x: int) = ()
f ""

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-Diagnosticsmistakes and possible improvements to diagnosticsBugImpact-Low(Internal MS Team use only) Describes an issue with limited impact on existing code.

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions