dotnet / fsharp

The F# compiler, F# core library, F# language service, and F# tooling integration for Visual Studio
https://dotnet.microsoft.com/languages/fsharp
MIT License
3.88k stars 783 forks source link

match expressions missing inside task ce confusing error #15748

Open jkone27 opened 1 year ago

jkone27 commented 1 year ago

is this related to the same? this is annoying with match expressions inside task ce...

image

in my case the reason was just the missing _ in: | _ -> for all cases, so I think the error is misleading, should suggest missing match case instead.

i didn't see it right away because the compiler error was not useful...

Originally posted by @jkone27 in https://github.com/dotnet/fsharp/issues/4653#issuecomment-1662393389

nojaf commented 1 year ago

Interestingly enough, I believe this only happens when there is no space between | and ->.

AST without space

AST with space

Without the space, the |-> is considered to be an operator. Perhaps this is more something an IDE could point out, that you probably meant | _ ->. I'm not sure though.

jkone27 commented 1 year ago

here is a small test fsx to give it a go


type SomeUnion =
    | First
    | Second
    | Third

let testMatch su =
    match su with
    | First -> "hey"
    |-> "hello"  // should maybe hint | _ -> or match case is given (?) 

let testMatchTwo su =
    task { 
        let z = Some(1)

        match z with
        |Some(n) -> 
            return ""
        |->    // should maybe hint | _ -> or match case is given (?) error disappears here
            let! x = Task.Delay(200)
            return "hello"  // construct may only be used inside a CE (?) no mention of |->
    }