In some cases compiler is unable to resolve type variable inside backrgroundTask or task computation expressions, but manifests it in "FS0073: internal error: Undefined or unsolved type variable" on unrelated line.
Bug seems to be related only to task computation expression. It compiles fine for other monads e.g. Async
Repro steps
Try to compile following module (reproduces both in F# 6 with FSharp.Core 6.0.3, or F# 7 with FSharp.Core 7.0.0)
module UnresolvedTypeVarBug
type IMarker<'T> = interface end
type SomeAction<'T when 'T :> IMarker<'T>> = SomeAction of list<'T>
type Spec<'Action> = { Dummy: unit }
open System.Threading.Tasks
let dummyTask (_spec: Spec<'Action>) (_action: 'Action) : Task<Result<int, string>> = failwith "not implemented"
let repro (spec: Spec<SomeAction<'T>>)
: Task<Result<unit, string>> =
// reproduces with task or backgroundTask CE
// compiles successfully with Async CE !
backgroundTask {
// bug is in next two lines
let action = SomeAction []
let! res = dummyTask spec action
match res with
| Ok _ ->
return Ok ()
| Error err ->
return Error err
}
Expected behavior
Code compiles successfully, like Intellisense suggests.
Or compiler suggests to qualify type on the relevant line (see workarounds)
Actual behavior
Two identical errors emitted, one for each return line:
error FS0073: internal error: Undefined or unsolved type variable: 'T
Known workarounds
I found two:
Specify type of action explicitly:
let action : SomeAction<'T> = SomeAction []
Inline action value into the call:
let! res = dummyTask spec (SomeAction [])
Related information
Provide any related information (optional):
Windows
net6 or net7 , reproduces on latest SDK at time of report (7.0.100)
I am running into the same issue, but oddly enough if I compile using dotnet build I get the error above; if I build from Visual Studio I don't get an error. I've only tested with SDK version 6.0.400 though.
In some cases compiler is unable to resolve type variable inside
backrgroundTask
ortask
computation expressions, but manifests it in "FS0073: internal error: Undefined or unsolved type variable" on unrelated line.Bug seems to be related only to task computation expression. It compiles fine for other monads e.g.
Async
Repro steps
Try to compile following module (reproduces both in F# 6 with FSharp.Core 6.0.3, or F# 7 with FSharp.Core 7.0.0)
Expected behavior
Code compiles successfully, like Intellisense suggests. Or compiler suggests to qualify type on the relevant line (see workarounds)
Actual behavior
Two identical errors emitted, one for each
return
line:Known workarounds
I found two:
let action : SomeAction<'T> = SomeAction []
let! res = dummyTask spec (SomeAction [])
Related information
Provide any related information (optional):