Skip to content

FS0748 error "This construct may only be used in computation expresions" reported for 'return' when it is not true #4653

@abelbraaksma

Description

@abelbraaksma

I knew I was testing potentially invalid code, but I was surprised to see the error:

image

Or in text for googleability:

FS0748: This construct may only be used within computation expressions. To return a value from an ordinaty function simply write the expression without 'return'.

Repro steps

Use something like return 1, return 2 at the end of any computation expression.

Expected behavior

Some syntax error, but not the one mentioned above.

Actual behavior

Error FS0748 as mentioned is reported, but the error says I am not inside a computation expression, while I am.

Known workarounds

Don't listen to the error, but fix your code ;).

Related information

As an aside (as always): it would be interesting to here thoughts on allowing return x, return y, but I'm not sure if we can get the behavior defined cleanly. My expectation would be that it would return a tuple of two instances of the computation expression.

  • Seen in VS 15.6 and 15.7, but likely the same in any recent version.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    New

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions