-
Notifications
You must be signed in to change notification settings - Fork 790
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
"try with" within seq fails to capture exception variable #17930
Comments
This is indeed a bug related to how try-with in seq gets lowered during compilation into a state machine. As a workaround, you can accomplish the goal by abstracting the check into an active pattern: open System
let (|AggCanceled|_|) (exn:Exception) =
match exn with
| :? AggregateException as exc when (exc.InnerException :? OperationCanceledException) -> Some exc
| _ -> None
let seqSample () : int seq =
seq {
try
printfn "Hi"
with
| AggCanceled ac -> yield ac.InnerExceptions.GetHashCode()
}
Will this help in your use case? |
@T-Gro This probably can help me, but I have already rewrote code to something different to get job done. But this is still a bug which will be fixed at some point in time, right? |
Yes, it is a bug and needs fixing. |
Disregard my (now deleted) comment. In .NET 6 we had the following:
Which has changed in #14540 In rc2 we fail to bind |
F# code like
fails to be compiled because
exc
is not available in(exc.InnerException :? Some2Exception)
environment.This probably happens somewhere within part of compiler which transforms computational expressions into calls to builder.
Repro steps
Here is minimal source code with bug.
Expected behavior
when
cases oftry with
withinseq
can access exception variable;try with
withinseq
before version 8.0. If my case is not allowed by design, then a good readable warning by compiler;Actual behavior
Compilation fails with
Undefined value 'exc'
.Related information
8.0.403
;12.8.401.0 for F# 8.0
;The text was updated successfully, but these errors were encountered: