Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

internal error: Undefined or unsolved type variable: ^TaskLike in backgroundTask CE #12931

Closed
TheAngryByrd opened this issue Apr 2, 2022 · 1 comment
Labels

Comments

@TheAngryByrd
Copy link
Contributor

👋 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 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:

 member __.Source(task: Task<'T>) : Async<'T> =
     Async.AwaitTask(task)

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

        type CancellableTaskResultBuilder with
            
            [<NoEagerConstraintApplication>]
            member inline this.Source< ^TaskLike, ^Awaiter, 'T, 'Error when ^TaskLike: (member GetAwaiter : unit -> ^Awaiter) and ^Awaiter :> ICriticalNotifyCompletion and ^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

type BackgroundCancellableTaskResultBuilder with
            [<NoEagerConstraintApplication>]
            member inline this.Source< ^TaskLike, ^Awaiter, 'T, 'Error when ^TaskLike: (member GetAwaiter : unit -> ^Awaiter) and ^Awaiter :> ICriticalNotifyCompletion and ^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.

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 of backgroundTask for Source 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
@dsyme
Copy link
Contributor

dsyme commented Apr 4, 2022

This is a duplicate of #12761

@dsyme dsyme closed this as completed Apr 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants