-
Notifications
You must be signed in to change notification settings - Fork 831
Labels
Area-Compiler-CheckingType checking, attributes and all aspects of logic checkingType checking, attributes and all aspects of logic checkingBug
Milestone
Description
F# code like
seq {
try
...
with
| :? SomeException as exc when (exc.InnerException :? Some2Exception)
}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.
module Program
open System
// This is OK
let sample () =
try
printfn "Hi"
with
| :? AggregateException as exc when (exc.InnerException :? OperationCanceledException) ->
()
// This is OK
let asyncSample () : Async<unit> =
async {
try
printfn "Hi"
with
| :? AggregateException as exc when (exc.InnerException :? OperationCanceledException) -> ()
}
(*
** This fails with
** 0>Program.fs(26,9): Error FS0971 : Undefined value 'exc'
** 0>Program.fs(26,9): Error FS0971 : Undefined value 'exc'
** 0>Program.fs(26,9): Error FS0971 : Undefined value 'exc'
** 0>Program.fs(26,9): Error FS0971 : Undefined value 'exc'
** 0>Program.fs(26,9): Error FS0971 : Undefined value 'exc'
*)
let seqSample () : int seq =
seq {
try
printfn "Hi"
with
| :? AggregateException as exc when (exc.InnerException :? OperationCanceledException) -> ()
}
// This is OK
let seqSample2 () : int seq =
seq {
try
printfn "Hi"
with
| :? AggregateException as exc when (true) -> ()
}
[<EntryPoint>]
let main argv =
0Expected behavior
- Code compiles,
whencases oftry withwithinseqcan access exception variable; - OR As far as I remember, F# didn't have support for
try withwithinseqbefore 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
- dotnet version
8.0.403; - F# version
12.8.401.0 for F# 8.0; - Rider and Visual Studio(Ionide) code show no red lines near problematic lines;
Metadata
Metadata
Assignees
Labels
Area-Compiler-CheckingType checking, attributes and all aspects of logic checkingType checking, attributes and all aspects of logic checkingBug
Type
Projects
Status
Done