Skip to content

Nested let! should compile #19457

@Martin521

Description

@Martin521

A let! nested in a simple let binding is currently not allowed by the compiler.

Example:

let y() =
    task {
        let a =
            let! b = System.IO.File.ReadAllLinesAsync("")
            b
        return a
    }

The 4th line produces error FS0750: This construct may only be used within computation expressions.
(Except for SDK 10.0, where the let! is silently compiled as a simple let, see #19456.)

I believe this behavior is a bug and the above example should compile correctly.

The spec, as quoted here, prescribes the following transformations:

{{ let binding in cexpr }} => let binding in {{ cexpr }} and
{{ let! pattern = expr in cexpr }} => builder.Bind(expr, (fun pattern -> {{ cexpr }}))

It seems that applying them to the example code is straightforward and should lead to correct compilation of the CE rather than to an error message.

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    Projects

    Status

    New

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions