Skip to content

Commit f59467b

Browse files
committed
Tests: add tests for rule 85
For mutually-recursive functions (defined with `let rec` and `and`).
1 parent 3924085 commit f59467b

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

tests/FSharpLint.Core.Tests/Rules/Conventions/EnsureTailCallDiagnosticsInRecursiveFunctions.fs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,33 @@ module Bar =
4444
"""
4545

4646
Assert.IsTrue this.NoErrorsExist
47+
48+
[<Test>]
49+
member this.``Should error when functions are mutually recursive, but one of them has no [<TailCall>] attribute``() =
50+
this.Parse """
51+
[<TailCall>]
52+
let rec Foo someParam =
53+
if someParam then
54+
Foo false
55+
else
56+
Bar()
57+
and Bar () =
58+
Foo true
59+
"""
60+
61+
Assert.IsTrue <| this.ErrorExistsAt(8, 4)
62+
63+
[<Test>]
64+
member this.``Should not error when functions are mutually recursive, and both of them have [<TailCall>] attribute``() =
65+
this.Parse """
66+
[<TailCall>]
67+
let rec Foo someParam =
68+
if someParam then
69+
Foo false
70+
else
71+
Bar()
72+
and [<TailCall>] Bar () =
73+
Foo true
74+
"""
75+
76+
Assert.IsTrue this.NoErrorsExist

0 commit comments

Comments
 (0)