fsprojects / FSharpLint

Lint tool for F#
https://fsprojects.github.io/FSharpLint/
MIT License
300 stars 73 forks source link

New rule: EnsureTailCallDiagnosticsInRecursiveFunctions #651

Closed knocte closed 4 months ago

knocte commented 6 months ago

Description

Context: https://stackoverflow.com/questions/806712/how-do-i-know-if-a-function-is-tail-recursive-in-f/77532717#77532717

Testcases

Should error:

let rec Foo someParam =
    if someParam then
        Foo()
    else
        ()

Should not error:

[<TailCall>]
let rec Foo someParam =
    if someParam then
        Foo()
    else
        ()

Should error (but with different error message):

let rec Foo someParam =
    ()

In the latter testcase, error message should be same as this rule's err msg: https://github.com/fsprojects/FSharpLint/issues/650 (please don't violate DRY). Otherwise, the error message should advise both about adding the TailCall attribute and <WarningsAsErrors>FS3569</WarningsAsErrors> (NOTE: it should also mention that this feature requires .NETv8.0 or newer).

knocte commented 6 months ago

@webwarrior-ws can you pick this one up when you have time. BTW:

error message should be same as this rule's err msg: https://github.com/fsprojects/FSharpLint/issues/650 (please don't violate DRY).

The above should mean that you should start from Mershad's branch because I haven't merged that PR yet. Thanks