Skip to content

Commit 9b0021e

Browse files
Add regression test for #3783: Mutually recursive computation expression NullReferenceException (#19613)
Test both function-scoped and type-constructor-scoped variants of mutually recursive sequence expressions to verify the NullReferenceException no longer occurs. Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 27640fd commit 9b0021e

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

tests/FSharp.Compiler.ComponentTests/Conformance/Expressions/ComputationExpressions/ComputationExpressions.fs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,3 +321,46 @@ module LetUseBangTests =
321321
(Error 748, Line 4, Col 13, Line 4, Col 20,
322322
"This construct may only be used within computation expressions. To return a value from an ordinary function simply write the expression without 'return'.")
323323
]
324+
325+
// https://github.com/dotnet/fsharp/issues/3783
326+
[<Fact>]
327+
let ``Issue 3783 - Mutually recursive computation expression should not raise NullReferenceException`` () =
328+
FSharp """
329+
#nowarn "40"
330+
#nowarn "21"
331+
332+
let x () =
333+
let rec a = seq {
334+
yield 0
335+
yield! b () }
336+
and b () = seq {
337+
yield 1
338+
yield! a }
339+
Seq.take 10 a |> Seq.toList
340+
341+
type A () =
342+
let test =
343+
let rec a = seq {
344+
yield 0
345+
yield! b () }
346+
and b () = seq {
347+
yield 1
348+
yield! a }
349+
Seq.take 10 a |> Seq.toList
350+
member _.Test = test
351+
352+
[<EntryPoint>]
353+
let main _ =
354+
let result1 = x ()
355+
if result1 <> [0; 1; 0; 1; 0; 1; 0; 1; 0; 1] then
356+
failwithf "Function variant failed: %A" result1
357+
358+
let a = A()
359+
if a.Test <> [0; 1; 0; 1; 0; 1; 0; 1; 0; 1] then
360+
failwithf "Type constructor variant failed: %A" a.Test
361+
362+
0
363+
"""
364+
|> asExe
365+
|> compileExeAndRun
366+
|> shouldSucceed

0 commit comments

Comments
 (0)