Skip to content

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

Description

@ljb

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

Activity

  1. added this to the Backlog milestone on Oct 18, 2024
  2. 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[/+] on Oct 18, 2024
  3. dawedawe commented on Oct 20, 2024

    @dawedawe
    Contributor

    Thanks for reporting. Will take a look soon.

  4. added
    Area-Compiler-CheckingType 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 on Oct 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-Compiler-CheckingType checking, attributes and all aspects of logic checkingBugImpact-Low(Internal MS Team use only) Describes an issue with limited impact on existing code.

    Type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions