dotnet / fsharp

The F# compiler, F# core library, F# language service, and F# tooling integration for Visual Studio
https://dotnet.microsoft.com/languages/fsharp
MIT License
3.89k stars 784 forks source link

`TailCall` attribute incorrectly warning #17604

Closed Smaug123 closed 1 month ago

Smaug123 commented 1 month ago

The [<TailCall>] attribute warns about a piece of code which is tail recursive and which empirically is not subject to stack overflows.

Repro steps

Provide the steps required to reproduce the problem:

module Foo =
    [<TailCall>]
    let rec go (args: string list) =
        match args with
        | [] -> ()
        | "--" :: _ -> ()
        | arg :: args -> go args

The second match clause is required. Without that, this compiles successfully. Problem reproduces in debug and release mode.

Expected behavior

Compiles successfully

Actual behavior

Error FS3569 : The member or function 'go' has the 'TailCallAttribute' attribute, but is not being used in a tail recursive way. This doesn't seem to be affecting the actual compilation; just a faulty warning.

Known workarounds

none

Related information

Provide any related information (optional):

> dotnet info
.NET SDK:
 Version:           8.0.303
 Commit:            29ab8e3268
 Workload version:  8.0.300-manifests.c915c39d
 MSBuild version:   17.10.4+10fbfbf2e

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  14.5
 OS Platform: Darwin
 RID:         osx-arm64
 Base Path:   /nix/store/qyz2wdl8lqvch8ny038nh0p9sqa9zg5j-dotnet-sdk-8.0.303/sdk/8.0.303/

.NET workloads installed:
There are no installed workloads to display.

Host:
  Version:      8.0.7
  Architecture: arm64
  Commit:       2aade6beb0

.NET SDKs installed:
  8.0.303 [/nix/store/qyz2wdl8lqvch8ny038nh0p9sqa9zg5j-dotnet-sdk-8.0.303/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 8.0.7 [/nix/store/qyz2wdl8lqvch8ny038nh0p9sqa9zg5j-dotnet-sdk-8.0.303/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 8.0.7 [/nix/store/qyz2wdl8lqvch8ny038nh0p9sqa9zg5j-dotnet-sdk-8.0.303/shared/Microsoft.NETCore.App]

Other architectures found:
  None

Environment variables:
  Not set

global.json file:
  /Users/patrick/Documents/GitHub/WoofWare.Myriad/global.json

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download
psfinaki commented 1 month ago

@dawedawe Maybe this would ring a bell for you

dawedawe commented 1 month ago

@dawedawe Maybe this would ring a bell for you

I'll try to find some time in a couple of days to look into it.