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
{{ message }}
try catch inside of task does not compile correctly, requires return value even if exception is thrown #15419
Area-Compiler-StateMachinesSequence, list, task and other state machine compilationBugImpact-Medium(Internal MS Team use only) Describes an issue with moderate impact on existing code.
overridethis.SendAsync(request,cancellationToken)=letwrapped=new AsyncCallableHandler(base.InnerHandler)letresponse=new HttpResponseMessage(System.Net.HttpStatusCode.Ambiguous)task{trylet!x= wrapped.CallSendAsync(request, cancellationToken)if x.IsSuccessStatusCode |>notthen
response.Content <- JsonContent.Create({| Path = request.RequestUri.AbsolutePath |})return response
elsereturn x
with ex ->
failwith ex.Message
//return response}
and the result is a compiler exception
Expected behavior
The task CE compiles fine knowing that if an exception is thrown, no other types will be returned after
Actual behavior
When throwing or rethrowing an exception in with (catch) block, Task CE/compiler still expects a matching type T response, instead of seeing that an exception is returned and not requiring a type
Known workarounds
provide a return type after the exception is rethrown
with ex ->
failwith ex.Message
return response //workaround
Area-Compiler-StateMachinesSequence, list, task and other state machine compilationBugImpact-Medium(Internal MS Team use only) Describes an issue with moderate impact on existing code.
Activity
Happypig375 commentedon Jul 1, 2023
Can be solved with implicit return fsharp/fslang-suggestions#1115