Skip to content

TaskBuilder allowing two return statements in one expression #16626

@MikeKing1994

Description

@MikeKing1994

When using task computation expressions it's possible to have two return or return! statements in a row. In this case both the functions called by return/return! are executed, which wouldn't be the expected behavior according to the usually assumed meaning of return.

This can be replicated with the following code, in this case you'll see both "functionA executed" and "functionB executed" printed to the console.

`open FSharp.Core
open FSharp.Control.TaskBuilder

let functionA() =
task {
printfn "functionA executed"
}

let functionB() =
task {
printfn "functionB executed"
}

let main() =
task {
return! functionB()
return! functionA()
}

main() |> Async.AwaitTask |> Async.RunSynchronously`

Whilst computation expressions in general could allow this depending on the definition of the builder, I would argue that the standard TaskBuilder should define return in the canonical sense.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-ComputationExpressionsEnd-to-end experience for computation expressions (except async and state machine compilation)Resolution-By Design

    Type

    No type

    Projects

    Status

    Done

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions