Recently I discovered that we got a stack overflow for a function that we had the TailCallAttribute on. It seems that the check doesn't work well for functions that uses use to dispose resources.
Repro steps
// Causes as warning which is expected. Causes a stack overflow
[<TailCall>]
let rec example1 () =
let path = Path.GetTempFileName()
use file = File.Open(path, FileMode.Open)
example1 ()
// Does not cause a warning even tough it causes a stack overflow
[<TailCall>]
let rec example2 () =
let path = Path.GetTempFileName()
use file = File.Open(path, FileMode.Open)
printfn "Hi!"
example2 ()
Compile the code above. example1 results in warning as expected. example2 does not result in a warning.
A zip-file with this example is attached. Running dotnet build only gives a warning for the first function.
RecursionExample.zip
Expected behavior
Both functions should result in warnings regarding the TailCallAttribute.
Actual behavior
Only example1 results in a warning.
Known workarounds
In code reviews manually check that functions marked with TailCallAttribute doesn't use use.
Related information
- Windows 11
- .NET SDK 8.0.403
- FSharp.Core 8.0.401
Recently I discovered that we got a stack overflow for a function that we had the
TailCallAttributeon. It seems that the check doesn't work well for functions that usesuseto dispose resources.Repro steps
Compile the code above.
example1results in warning as expected.example2does not result in a warning.A zip-file with this example is attached. Running
dotnet buildonly gives a warning for the first function.RecursionExample.zip
Expected behavior
Both functions should result in warnings regarding the
TailCallAttribute.Actual behavior
Only
example1results in a warning.Known workarounds
In code reviews manually check that functions marked with
TailCallAttributedoesn't useuse.Related information