Skip to content

Commit

Permalink
Bugfix:: Make bound values available to filter clause for try-with in…
Browse files Browse the repository at this point in the history
… seq{} (#17990)
  • Loading branch information
T-Gro authored Nov 11, 2024
1 parent fce13a2 commit 8a4c053
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/release-notes/.FSharp.Compiler.Service/9.0.200.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* Fix nullness inference for member val and other OO scenarios ([PR #17845](https://github.com/dotnet/fsharp/pull/17845))
* Fix internal error when analyzing incomplete inherit member ([PR #17905](https://github.com/dotnet/fsharp/pull/17905))
* Fix missing nullness warning in case of method resolution multiple candidates ([PR #17917](https://github.com/dotnet/fsharp/pull/17918))
* Fix failure to use bound values in `when` clauses of `try-with` in `seq` expressions ([# 17990](https://github.com/dotnet/fsharp/pull/17990))

### Added

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ let TcSequenceExpression (cenv: TcFileState) env tpenv comp (overallTy: OverallT
MatchClause(patR, condR, TTarget(vspecs, matchBody, None), patR.Range)

let filterClause =
MatchClause(patR, condR, TTarget([], Expr.Const(Const.Int32 1, m, g.int_ty), None), patR.Range)
MatchClause(patR, condR, TTarget(vspecs, Expr.Const(Const.Int32 1, m, g.int_ty), None), patR.Range)

(handlerClause, filterClause), tpenv)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,54 @@ if sum <> 110 then
|> runCode
|> shouldSucceed

[<Fact>]
let ``With clause in seq expression can bind specific exn type``() =

Fsx """
open System
let whatIsIt =
seq {
try
yield 1
with
| :? AggregateException as exc when (exc.InnerException :? OperationCanceledException) -> ()
}
|> Seq.head
"""
|> compile
|> verifyIL [
"""IL_0000: ldarg.1
IL_0001: isinst [runtime]System.AggregateException
IL_0006: stloc.0
IL_0007: ldloc.0""";

"""IL_000a: ldloc.0
IL_000b: callvirt instance class [runtime]System.Exception [runtime]System.Exception::get_InnerException()
IL_0010: stloc.1
IL_0011: ldloc.1
IL_0012: isinst [runtime]System.OperationCanceledException"""]

[<Fact>]
let ``With clause in seq expression can bind many exn subtypes``() =

Fsx """
open System
let whatIsIt =
seq {
try
yield (10/0)
with
| :? AggregateException as exc when (exc.InnerException :? OperationCanceledException) -> ()
| :? AggregateException as exagg when (exagg.InnerExceptions.GetHashCode()) = 15 -> yield (exagg.InnerExceptions.GetHashCode())
| :? AggregateException as exagg -> yield (exagg.InnerExceptions.GetHashCode())
| :? DivideByZeroException as exn when exn.Message = "abc" -> yield 0
| _ -> yield 1
}
|> Seq.head
"""
|> runCode
|> shouldSucceed

[<Theory>]
[<InlineData("41","42","43")>]
[<InlineData("()","42","43")>]
Expand Down

0 comments on commit 8a4c053

Please sign in to comment.