From d566f53680bf72ec0bec92d84ca2315896dd9266 Mon Sep 17 00:00:00 2001 From: dawe Date: Tue, 29 Oct 2024 12:19:27 +0100 Subject: [PATCH] Fix missing TailCall warning in Sequential in use scope, #17897 (#17927) --- .../.FSharp.Compiler.Service/9.0.200.md | 1 + src/Compiler/Checking/TailCallChecks.fs | 1 + .../ErrorMessages/TailCallAttribute.fs | 28 +++++++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/docs/release-notes/.FSharp.Compiler.Service/9.0.200.md b/docs/release-notes/.FSharp.Compiler.Service/9.0.200.md index c0c5b75b95..9798a50e6e 100644 --- a/docs/release-notes/.FSharp.Compiler.Service/9.0.200.md +++ b/docs/release-notes/.FSharp.Compiler.Service/9.0.200.md @@ -1,5 +1,6 @@ ### Fixed +* Fix missing TailCall warning in Sequential in use scope ([PR #17927](https://github.com/dotnet/fsharp/pull/17927)) * Fix false negatives for passing null to "obj" arguments. Only "obj | null" can now subsume any type ([PR #17757](https://github.com/dotnet/fsharp/pull/17757)) * Fix internal error when calling 'AddSingleton' and other overloads only differing in generic arity ([PR #17804](https://github.com/dotnet/fsharp/pull/17804)) * Fix extension methods support for non-reference system assemblies ([PR #17799](https://github.com/dotnet/fsharp/pull/17799)) diff --git a/src/Compiler/Checking/TailCallChecks.fs b/src/Compiler/Checking/TailCallChecks.fs index d23b50716a..a7ea9ad802 100644 --- a/src/Compiler/Checking/TailCallChecks.fs +++ b/src/Compiler/Checking/TailCallChecks.fs @@ -792,6 +792,7 @@ let CheckModuleBinding cenv (isRec: bool) (TBind _ as bind) = // warn for recursive calls in TryWith/TryFinally operations exprs |> Seq.iter (checkTailCall true) | Expr.Op(args = exprs) -> exprs |> Seq.iter (checkTailCall insideSubBindingOrTry) + | Expr.Sequential(expr2 = expr2) -> checkTailCall insideSubBindingOrTry expr2 | _ -> () checkTailCall false bodyExpr diff --git a/tests/FSharp.Compiler.ComponentTests/ErrorMessages/TailCallAttribute.fs b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/TailCallAttribute.fs index 4eb2d3b2a1..693833ef4b 100644 --- a/tests/FSharp.Compiler.ComponentTests/ErrorMessages/TailCallAttribute.fs +++ b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/TailCallAttribute.fs @@ -473,6 +473,34 @@ namespace N "The member or function 'f' has the 'TailCallAttribute' attribute, but is not being used in a tail recursive way." } ] + [] + let ``Warn for rec call in Sequential in use scope`` () = + """ +namespace N + + module M = + + [] + let rec f () = + let path = System.IO.Path.GetTempFileName() + use file = System.IO.File.Open(path, System.IO.FileMode.Open) + printfn "Hi!" + f () + """ + |> FSharp + |> withLangVersion80 + |> compile + |> shouldFail + |> withResults [ + { Error = Warning 3569 + Range = { StartLine = 11 + StartColumn = 13 + EndLine = 11 + EndColumn = 14 } + Message = + "The member or function 'f' has the 'TailCallAttribute' attribute, but is not being used in a tail recursive way." } + ] + [] let ``Warn for invalid tailcalls in async expression`` () = """