Skip to content

Allow CE return and type annotations to play well together without needing parentheses #15788

@jwosty

Description

@jwosty

Is your feature request related to a problem? Please describe.

I was surprised to learn that the parser doesn't like it when you use a type annotation with return in a CE:

open System

type MyType() =
    interface IDisposable with
        member this.Dispose () = ()

let f () = async {
    // Compile errors here
    return new MyType() : IDisposable
}

Describe the solution you'd like

It would be nice if this didn't result in a compile error. I understand that it's pretty low-impact (because workarounds are very easy here), and that the error probably has to do with parser precedence rules, but it would be a nice-to-have if the fix turns out to be simple. Otherwise, I'm not too broken up about it.

Describe alternatives you've considered

I was also surprised that :> (the upcast operator) works in the same situation:

let f () = async {
    return new MyType() :> IDisposable
}

Other workarounds:

let f () : Async<IDisposable> = async {
    return new MyType()
}
let f () = async {
    return (new MyType() : IDisposable)
}

Additional context

Related: #11481

Metadata

Metadata

Assignees

Projects

Status

Done

Relationships

None yet

Development

No branches or pull requests

Issue actions