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

Closed
ljb opened this issue Oct 18, 2024 · 1 comment · Fixed by #17927
Closed
Labels
Area-Compiler-Checking Type checking, attributes and all aspects of logic checking Bug Impact-Low (Internal MS Team use only) Describes an issue with limited impact on existing code.
Milestone

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
@dawedawe
Copy link
Contributor

Thanks for reporting. Will take a look soon.

@abonie abonie added Area-Compiler-Checking Type checking, attributes and all aspects of logic checking Impact-Low (Internal MS Team use only) Describes an issue with limited impact on existing code. and removed Needs-Triage labels Oct 21, 2024
dawedawe added a commit to dawedawe/fsharp that referenced this issue Oct 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compiler-Checking Type checking, attributes and all aspects of logic checking Bug Impact-Low (Internal MS Team use only) Describes an issue with limited impact on existing code.
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants