dotnet / dotnet/fsharp

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

Open
#4,653 4 comments 1 reaction 0 assignees View on GitHub
Feature Improvement
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 11h
Merged PRs (30d)
131

Description

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

![image](https://user-images.githubusercontent.com/16015770/38167752-7df1c4e4-353b-11e8-844f-9620559ad724.png)

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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.