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
This code should either compile with no problems, or at least produce a compiler error on the return line (as I understand that usually F# won't automatically upcast Task<List<string>> to Task<IList<string>>).
Actual behavior
A type error is emitted on the first let! line, which is NOT the actual source of the typing error:
let! x = task { return 42 }
----^^^^^^^^^^^^^^^^^^^^^^^^^^^
/stdin(5,5): error FS0193: Type constraint mismatch. The type
'TaskCode<List<'a>,List<'a>>'
is not compatible with type
'TaskCode<IList<string>,IList<string>>'
This is particularly confusing when there's a lot of code between the first let! and the final return and/or if the let! is a very complex expression, as it leads you to look in the entirely wrong place for the problem.
Known workarounds
Add an extra annotation on the return line, like so:
I ended up hitting this yesterday while converting older task CE's to the F# built in one.
Another example:
// Worksletfoo():int64 =6letotherAsync()=async{return"lol"}letfooAsync():Async<int64>=async{let!_= otherAsync ()return6}// Doesn't work//Type constraint mismatch. The type // 'TaskCode<int,int>' // is not compatible with type// 'TaskCode<int64,int64>' letotherTask=task{return"lol"}letfooTask():Task<int64>=task{let!_= otherTask ()return6}
Not sure whether or not this is a bug, or should be a feature request, but I ran into this and found it incredibly confusing.
It seems that the
task
CE produces certain kinds of typing errors on the wrong lines, where the equivalentasync
expression produces no errors at all.Repro Steps
Compile the following code:
Expected behavior
This code should either compile with no problems, or at least produce a compiler error on the
return
line (as I understand that usually F# won't automatically upcastTask<List<string>>
toTask<IList<string>>
).Actual behavior
A type error is emitted on the first
let!
line, which is NOT the actual source of the typing error:This is particularly confusing when there's a lot of code between the first
let!
and the finalreturn
and/or if thelet!
is a very complex expression, as it leads you to look in the entirely wrong place for the problem.Known workarounds
Add an extra annotation on the
return
line, like so:Related Information
It should be noted that this does not occur in equivalent
async
expressions:The text was updated successfully, but these errors were encountered: