dotnet / dotnet/fsharp

Confusing/incorrect type mismatch message in async CE

Open
#14,437 0 comments 1 reaction 0 assignees View on GitHub
Area-Diagnostics Bug Impact-Low
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 22h
Merged PRs (30d)
144

Description

Consider this code (type annotations added for clarity):

```f#
async {
let asyncUnitArr : Async = 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](https://user-images.githubusercontent.com/7766733/205879479-e5ca339c-57c2-4127-be40-2aed404ee086.png)

I find this confusing for two reasons.

Firstly, the expression that is underlined, `asyncUnitArr`, has the type `Async`, 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` and (given the context) is _expected_ to have the type `Async`.

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

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

![image](https://user-images.githubusercontent.com/7766733/205880302-108c1817-dc1c-433c-bef3-6e9dd5688845.png)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.