Skip to content

Improve error reporting: Recursive async functions #1170

@isaacabraham

Description

@isaacabraham

What

The following code snippet leads to the resulting error message: -

let rec foo() = async { return foo() }
Type mismatch. Expecting a
    'a    
but given a
    Async<'a>    
The resulting type would be infinite when unifying ''a' and 'Async<'a>'

Why

99/100 times the cause is simply that the developer has forgotten to return! rather than return. The current error message is confusing, does not explain why the error has occurred and does not present the likely solution.

How

Suggest a rewording that follows Error / Explanation / Suggestion format: -

Type mismatch. Expecting a
    'a    
but given a
    Async<'a>
You are attempting to recursively return the result of an asynchronous call which is not awaited. Have you forgotten to use 'return!' instead of 'return' ?

Perhaps someone could explain what an infinite type is as well - I have no idea, although I sort of understand why this error occurs... :-) As I don't, the "explanation" bit of this error needs reworking for sure. I know that common parlance is to use "Consider" but in this case it's a guess more than anything. I also don't like use of "await" but am not sure what the correct term is.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions