Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using TailCallAttribute on a function that uses use does not result in expected warning #17897

Open
ljb opened this issue Oct 18, 2024 · 0 comments

Comments

@ljb
Copy link

ljb commented Oct 18, 2024

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
@github-actions github-actions bot added this to the Backlog milestone Oct 18, 2024
@ljb ljb changed the title Using TailCall on a function that uses use does not result in expected warning Using TailCallAttribute on a function that uses use does not result in expected warning Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: New
Development

No branches or pull requests

1 participant