Skip to content

Commit 4026802

Browse files
Changes computation expression's Return to accept only unit.
Previously, Return accepted any type at all, but ignores the value. This leads to developers writing code like `return 1` which compiles but has no run-time effect, leaving the developer very confused. This computation expression's Return was not intended to be using explicitly with a `return` keyword but was added to allow the use of `do!`. This commit changes Return to only accept unit to no longer allow explicit calls to return passing a value, but continue to allow `do!`. Return is being removed from the signature file because of the inability to define the correct type signature. The signature is `unit -> AsyncSeq<'T>`, but the compiler interprets this as a function that has no parameters rather than a function that has a single parameter of type unit.
1 parent 3512018 commit 4026802

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

src/FSharp.Control.AsyncSeq/AsyncSeq.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ module AsyncSeq =
399399
// do! something
400400
//
401401
// because F# translates body as Bind(something, fun () -> Return())
402-
member x.Return _ = empty
402+
member x.Return () = empty
403403
member x.YieldFrom(s:AsyncSeq<'T>) =
404404
s
405405
member x.Zero () = empty

src/FSharp.Control.AsyncSeq/AsyncSeq.fsi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ module AsyncSeq =
9191
member For : source:AsyncSeq<'T> * action:('T -> AsyncSeq<'TResult>) -> AsyncSeq<'TResult>
9292

9393
/// Implements "return" for the asyncSeq computation builder.
94-
member Return : 'unit -> AsyncSeq<'T>
94+
// Commented because there does not seem to be a way to specify the correct parameter type to the compiler.
95+
// What is needed is one parameter of type unit, but the below is interpreted as zero parameters.
96+
//member Return : unit -> AsyncSeq<'T>
9597

9698
/// Implements "try-finally" for the asyncSeq computation builder.
9799
member TryFinally : body:AsyncSeq<'T> * compensation:(unit -> unit) -> AsyncSeq<'T>

0 commit comments

Comments
 (0)