You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm currently working on a cancellableTaskResult in FsToolkit.ErrorHandling. I've been following the pattern of set down in FSharp.Core by having a cancellableTaskResult and a backgroundCancellableTaskResult to deal with the SynchronizationContext behaviors. One of the differences I've been going down the path of is using Source members on the computation expressions to avoid needing a massive number of overloads with regards to Bind/ReturnFrom/MergeSources etc. The common pattern for Source is SomeOtherType -> TheTypeIKnowHowToBind. So for example, if you added Source members to AsyncBuilder, it would looking something like:
However, things get a bit weird when trying to implement against the SRTP ^TaskLike. Typically these extensions have been put on the Base builder but because of the SynchronizationContext, I've put this extension on the CancellableTaskResultBuilder. The way I've implemented is to use
typeCancellableTaskResultBuilderwith[<NoEagerConstraintApplication>]member inlinethis.Source<^TaskLike,^Awaiter,'T,'Errorwhen^TaskLike:(member GetAwaiter :unit ->^Awaiter)and^Awaiter:>ICriticalNotifyCompletionand^Awaiter:(member get_IsCompleted :unit ->bool)and^Awaiter:(member GetResult :unit ->'T)>(t:^TaskLike):CancellableTaskResult<'T,'Error>=// `CancellableTaskResult` is a `CancellationToken -> Task<Result<'T,'Error>>`fun _ ->task{let!result= t
return Ok result
}
Which works fine. However when adding a similar implementation to the BackgroundCancellableTaskResultBuilder
typeBackgroundCancellableTaskResultBuilderwith[<NoEagerConstraintApplication>]member inlinethis.Source<^TaskLike,^Awaiter,'T,'Errorwhen^TaskLike:(member GetAwaiter :unit ->^Awaiter)and^Awaiter:>ICriticalNotifyCompletionand^Awaiter:(member get_IsCompleted :unit ->bool)and^Awaiter:(member GetResult :unit ->'T)>(t:^TaskLike):CancellableTaskResult<'T,'Error>=fun _ ->
backgroundTask {let!result= t
return Ok result
}
I get multiple errors such as:
src/FsToolkit.ErrorHandling.IcedTasks/CancellableTaskResultCE.fs(380,21): error FS0073: internal error: Undefined or unsolved type variable: ^TaskLike [src/FsToolkit.ErrorHandling.IcedTasks/FsToolkit.ErrorHandling.IcedTasks.fsproj]
src/FsToolkit.ErrorHandling.IcedTasks/CancellableTaskResultCE.fs(380,21): error FS0073: internal error: Undefined or unsolved type variable: ^Awaiter [src/FsToolkit.ErrorHandling.IcedTasks/FsToolkit.ErrorHandling.IcedTasks.fsproj]
src/FsToolkit.ErrorHandling.IcedTasks/unknown(1,1): error FS0073: internal error: Undefined or unsolved type variable: ^TaskLike [src/FsToolkit.ErrorHandling.IcedTasks/FsToolkit.ErrorHandling.IcedTasks.fsproj]
src/FsToolkit.ErrorHandling.IcedTasks/unknown(1,1): error FS0073: internal error: Undefined or unsolved type variable: ^Awaiter [src/FsToolkit.ErrorHandling.IcedTasks/FsToolkit.ErrorHandling.IcedTasks.fsproj]
I've read over these issues #9633 and #12184 and many of the issues linked but I'm unsure where to go other than filing a bug at this point.
👋 Hey there.
I'm currently working on a
cancellableTaskResult
in FsToolkit.ErrorHandling. I've been following the pattern of set down in FSharp.Core by having acancellableTaskResult
and abackgroundCancellableTaskResult
to deal with the SynchronizationContext behaviors. One of the differences I've been going down the path of is usingSource
members on the computation expressions to avoid needing a massive number of overloads with regards toBind/ReturnFrom/MergeSources
etc. The common pattern forSource
isSomeOtherType
->TheTypeIKnowHowToBind
. So for example, if you addedSource
members to AsyncBuilder, it would looking something like:However, things get a bit weird when trying to implement against the SRTP
^TaskLike
. Typically these extensions have been put on theBase
builder but because of theSynchronizationContext
, I've put this extension on theCancellableTaskResultBuilder
. The way I've implemented is to useWhich works fine. However when adding a similar implementation to the
BackgroundCancellableTaskResultBuilder
I get multiple errors such as:
I've read over these issues #9633 and #12184 and many of the issues linked but I'm unsure where to go other than filing a bug at this point.
Repro steps
demystifyfp/FsToolkit.ErrorHandling#172 Should have the the weird compile errors
Expected behavior
Not getting this compile error.
Actual behavior
Getting this compile error.
Known workarounds
Just use
task
instead ofbackgroundTask
forSource
overloads using SRTP to bind for^TaskLike
Related information
Provide any related information (optional):
dotnet --info .NET SDK (reflecting any global.json): Version: 6.0.100 Commit: 9e8b04bbff Runtime Environment: OS Name: Mac OS X OS Version: 11.0 OS Platform: Darwin RID: osx.11.0-x64 Base Path: /usr/local/share/dotnet/sdk/6.0.100/ Host (useful for support): Version: 6.0.0 Commit: 4822e3c3aa .NET SDKs installed: 2.2.207 [/usr/local/share/dotnet/sdk] 3.1.201 [/usr/local/share/dotnet/sdk] 3.1.406 [/usr/local/share/dotnet/sdk] 3.1.407 [/usr/local/share/dotnet/sdk] 5.0.103 [/usr/local/share/dotnet/sdk] 5.0.201 [/usr/local/share/dotnet/sdk] 5.0.202 [/usr/local/share/dotnet/sdk] 5.0.208 [/usr/local/share/dotnet/sdk] 5.0.300 [/usr/local/share/dotnet/sdk] 5.0.402 [/usr/local/share/dotnet/sdk] 6.0.100 [/usr/local/share/dotnet/sdk] .NET runtimes installed: Microsoft.AspNetCore.All 2.2.8 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.2.8 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.3 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.12 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.13 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.3 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.4 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.5 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.6 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.11 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.0-preview.3.21201.13 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.2.8 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.3 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.12 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.13 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.3 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.4 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.5 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.6 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.11 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] To install additional .NET runtimes or SDKs: https://aka.ms/dotnet-download
The text was updated successfully, but these errors were encountered: