Skip to content

Commit 8a4c053

Browse files
authored
Bugfix:: Make bound values available to filter clause for try-with in seq{} (#17990)
1 parent fce13a2 commit 8a4c053

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

docs/release-notes/.FSharp.Compiler.Service/9.0.200.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* Fix nullness inference for member val and other OO scenarios ([PR #17845](https://github.com/dotnet/fsharp/pull/17845))
1111
* Fix internal error when analyzing incomplete inherit member ([PR #17905](https://github.com/dotnet/fsharp/pull/17905))
1212
* Fix missing nullness warning in case of method resolution multiple candidates ([PR #17917](https://github.com/dotnet/fsharp/pull/17918))
13+
* Fix failure to use bound values in `when` clauses of `try-with` in `seq` expressions ([# 17990](https://github.com/dotnet/fsharp/pull/17990))
1314

1415
### Added
1516

src/Compiler/Checking/Expressions/CheckSequenceExpressions.fs

+1-1
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ let TcSequenceExpression (cenv: TcFileState) env tpenv comp (overallTy: OverallT
340340
MatchClause(patR, condR, TTarget(vspecs, matchBody, None), patR.Range)
341341

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

345345
(handlerClause, filterClause), tpenv)
346346

tests/FSharp.Compiler.ComponentTests/Language/SequenceExpressions/SequenceExpressionTests.fs

+48
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,54 @@ if sum <> 110 then
335335
|> runCode
336336
|> shouldSucceed
337337

338+
[<Fact>]
339+
let ``With clause in seq expression can bind specific exn type``() =
340+
341+
Fsx """
342+
open System
343+
let whatIsIt =
344+
seq {
345+
try
346+
yield 1
347+
with
348+
| :? AggregateException as exc when (exc.InnerException :? OperationCanceledException) -> ()
349+
}
350+
|> Seq.head
351+
"""
352+
|> compile
353+
|> verifyIL [
354+
"""IL_0000: ldarg.1
355+
IL_0001: isinst [runtime]System.AggregateException
356+
IL_0006: stloc.0
357+
IL_0007: ldloc.0""";
358+
359+
"""IL_000a: ldloc.0
360+
IL_000b: callvirt instance class [runtime]System.Exception [runtime]System.Exception::get_InnerException()
361+
IL_0010: stloc.1
362+
IL_0011: ldloc.1
363+
IL_0012: isinst [runtime]System.OperationCanceledException"""]
364+
365+
[<Fact>]
366+
let ``With clause in seq expression can bind many exn subtypes``() =
367+
368+
Fsx """
369+
open System
370+
let whatIsIt =
371+
seq {
372+
try
373+
yield (10/0)
374+
with
375+
| :? AggregateException as exc when (exc.InnerException :? OperationCanceledException) -> ()
376+
| :? AggregateException as exagg when (exagg.InnerExceptions.GetHashCode()) = 15 -> yield (exagg.InnerExceptions.GetHashCode())
377+
| :? AggregateException as exagg -> yield (exagg.InnerExceptions.GetHashCode())
378+
| :? DivideByZeroException as exn when exn.Message = "abc" -> yield 0
379+
| _ -> yield 1
380+
}
381+
|> Seq.head
382+
"""
383+
|> runCode
384+
|> shouldSucceed
385+
338386
[<Theory>]
339387
[<InlineData("41","42","43")>]
340388
[<InlineData("()","42","43")>]

0 commit comments

Comments
 (0)