Skip to content

Commit a527f88

Browse files
committed
Fix build
1 parent 0d61b91 commit a527f88

File tree

3 files changed

+86
-31
lines changed

3 files changed

+86
-31
lines changed

src/FSharp.Core/tasks.fs

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,28 @@ module LowPriority =
370370
=
371371
ResumableCode.Using(resource, body)
372372

373+
type TaskBuilder with
374+
member inline this.MergeSources< ^TaskLike1, ^TaskLike2, ^TResult1, ^TResult2, ^Awaiter1, ^Awaiter2
375+
when ^TaskLike1: (member GetAwaiter: unit -> ^Awaiter1)
376+
and ^TaskLike2 : (member GetAwaiter: unit -> ^Awaiter2)
377+
and ^Awaiter1 :> ICriticalNotifyCompletion
378+
and ^Awaiter2 :> ICriticalNotifyCompletion
379+
and ^Awaiter1: (member get_IsCompleted: unit -> bool)
380+
and ^Awaiter1: (member GetResult: unit -> ^TResult1)
381+
and ^Awaiter2: (member get_IsCompleted: unit -> bool)
382+
and ^Awaiter2: (member GetResult: unit -> ^TResult2)>
383+
(task1: ^TaskLike1, task2: ^TaskLike2)
384+
: Task<^TResult1 * ^TResult2> =
385+
this.Run(
386+
this.Bind(task1, fun (result1: ^TResult1) ->
387+
this.Bind(task2, fun (result2: ^TResult2) ->
388+
this.Return(result1, result2)
389+
)
390+
)
391+
)
392+
373393
module HighPriority =
394+
374395
// High priority extensions
375396
type TaskBuilderBase with
376397

@@ -424,7 +445,21 @@ module HighPriority =
424445
member inline this.ReturnFrom(task: Task<'T>) : TaskCode<'T, 'T> =
425446
this.Bind(task, this.Return)
426447

448+
type TaskBuilder with
449+
450+
// This is required for type inference in tasks cases
451+
member inline this.MergeSources(task1: Task<^TResult1>, task2: Task<^TResult2>)
452+
: Task<^TResult1 * ^TResult2> =
453+
this.Run(
454+
this.Bind(task1, fun (result1: ^TResult1) ->
455+
this.Bind(task2, fun (result2: ^TResult2) ->
456+
this.Return(result1, result2)
457+
)
458+
)
459+
)
460+
427461
module MediumPriority =
462+
open LowPriority
428463
open HighPriority
429464

430465
// Medium priority extensions
@@ -438,19 +473,9 @@ module MediumPriority =
438473
member inline this.ReturnFrom(computation: Async<'T>) : TaskCode<'T, 'T> =
439474
this.ReturnFrom(Async.StartImmediateAsTask computation)
440475

476+
441477
type TaskBuilder with
442-
443-
// This is required for type inference in tasks cases
444-
member inline this.MergeSources(task1: Task<^TResult1>, task2: Task<^TResult2>)
445-
: Task<^TResult1 * ^TResult2> =
446-
this.Run(
447-
this.Bind(task1, fun (result1: ^TResult1) ->
448-
this.Bind(task2, fun (result2: ^TResult2) ->
449-
this.Return(result1, result2)
450-
)
451-
)
452-
)
453-
478+
454479
// This is required for type inference in tasks cases
455480
member inline this.MergeSources< ^TaskLike2, ^TResult1, ^TResult2, ^Awaiter2
456481
when ^TaskLike2 : (member GetAwaiter: unit -> ^Awaiter2)
@@ -482,22 +507,4 @@ module MediumPriority =
482507
)
483508
)
484509
)
485-
486-
member inline this.MergeSources< ^TaskLike1, ^TaskLike2, ^TResult1, ^TResult2, ^Awaiter1, ^Awaiter2
487-
when ^TaskLike1: (member GetAwaiter: unit -> ^Awaiter1)
488-
and ^TaskLike2 : (member GetAwaiter: unit -> ^Awaiter2)
489-
and ^Awaiter1 :> ICriticalNotifyCompletion
490-
and ^Awaiter2 :> ICriticalNotifyCompletion
491-
and ^Awaiter1: (member get_IsCompleted: unit -> bool)
492-
and ^Awaiter1: (member GetResult: unit -> ^TResult1)
493-
and ^Awaiter2: (member get_IsCompleted: unit -> bool)
494-
and ^Awaiter2: (member GetResult: unit -> ^TResult2)>
495-
(task1: ^TaskLike1, task2: ^TaskLike2)
496-
: Task<^TResult1 * ^TResult2> =
497-
this.Run(
498-
this.Bind(task1, fun (result1: ^TResult1) ->
499-
this.Bind(task2, fun (result2: ^TResult2) ->
500-
this.Return(result1, result2)
501-
)
502-
)
503-
)
510+

src/FSharp.Core/tasks.fsi

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,19 @@ module LowPriority =
239239
resource: 'Resource * body: ('Resource -> TaskCode<'TOverall, 'T>) -> TaskCode<'TOverall, 'T>
240240
when 'Resource :> IDisposable | null
241241

242+
type TaskBuilder with
243+
member inline MergeSources< ^TaskLike1, ^TaskLike2, ^TResult1, ^TResult2, ^Awaiter1, ^Awaiter2> :
244+
task1: ^TaskLike1 * task2: ^TaskLike2 ->
245+
Task<^TResult1 * ^TResult2>
246+
when ^TaskLike1: (member GetAwaiter: unit -> ^Awaiter1)
247+
and ^TaskLike2 : (member GetAwaiter: unit -> ^Awaiter2)
248+
and ^Awaiter1 :> ICriticalNotifyCompletion
249+
and ^Awaiter2 :> ICriticalNotifyCompletion
250+
and ^Awaiter1: (member get_IsCompleted: unit -> bool)
251+
and ^Awaiter1: (member GetResult: unit -> ^TResult1)
252+
and ^Awaiter2: (member get_IsCompleted: unit -> bool)
253+
and ^Awaiter2: (member GetResult: unit -> ^TResult2)
254+
242255
/// <summary>
243256
/// Contains medium-priority overloads for the `task` computation expression builder.
244257
/// </summary>
@@ -258,6 +271,25 @@ module MediumPriority =
258271
/// </summary>
259272
member inline ReturnFrom: computation: Async<'T> -> TaskCode<'T, 'T>
260273

274+
275+
type TaskBuilder with
276+
277+
member inline MergeSources< ^TaskLike2, ^TResult1, ^TResult2, ^Awaiter2> :
278+
task1: Task<^TResult1> * task2: ^TaskLike2 ->
279+
Task<^TResult1 * ^TResult2>
280+
when ^TaskLike2 : (member GetAwaiter: unit -> ^Awaiter2)
281+
and ^Awaiter2 :> ICriticalNotifyCompletion
282+
and ^Awaiter2: (member get_IsCompleted: unit -> bool)
283+
and ^Awaiter2: (member GetResult: unit -> ^TResult2)
284+
285+
member inline MergeSources< ^TaskLike1, ^TResult1, ^TResult2, ^Awaiter1> :
286+
task1: ^TaskLike1 * task2: Task<^TResult2> ->
287+
Task<^TResult1 * ^TResult2>
288+
when ^TaskLike1 : (member GetAwaiter: unit -> ^Awaiter1)
289+
and ^Awaiter1 :> ICriticalNotifyCompletion
290+
and ^Awaiter1: (member get_IsCompleted: unit -> bool)
291+
and ^Awaiter1: (member GetResult: unit -> ^TResult1)
292+
261293
/// <summary>
262294
/// Contains high-priority overloads for the `task` computation expression builder.
263295
/// </summary>
@@ -285,3 +317,8 @@ module HighPriority =
285317
task: Task<'TResult1> *
286318
continuation: ('TResult1 -> TaskCode<'TOverall, 'TResult2>) ->
287319
bool
320+
321+
type TaskBuilder with
322+
member inline MergeSources< ^TResult1, ^TResult2> :
323+
task1: Task<^TResult1> * task2: Task<^TResult2> ->
324+
Task<^TResult1 * ^TResult2>

tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Control/Tasks.fs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,17 @@ type SmokeTestsForCompilation() =
5353
t.Wait()
5454
if t.Result <> 1 then failwith "failed"
5555

56+
[<Fact>]
57+
member _.mergesrc() =
58+
task {
59+
let! x = Task.FromResult(1)
60+
and! y = Task.FromResult(2)
61+
return x + y
62+
}
63+
|> fun t ->
64+
t.Wait()
65+
if t.Result <> 3 then failwith "failed"
66+
5667
[<Fact>]
5768
member _.tbind() =
5869
task {

0 commit comments

Comments
 (0)