Skip to content
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

Bugfix:: Make bound values available to filter clause for try-with in seq{} #17990

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading