Skip to content

Commit d566f53

Browse files
authored
Fix missing TailCall warning in Sequential in use scope, #17897 (#17927)
1 parent 6860329 commit d566f53

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

docs/release-notes/.FSharp.Compiler.Service/9.0.200.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
### Fixed
22

3+
* Fix missing TailCall warning in Sequential in use scope ([PR #17927](https://github.com/dotnet/fsharp/pull/17927))
34
* 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))
45
* Fix internal error when calling 'AddSingleton' and other overloads only differing in generic arity ([PR #17804](https://github.com/dotnet/fsharp/pull/17804))
56
* Fix extension methods support for non-reference system assemblies ([PR #17799](https://github.com/dotnet/fsharp/pull/17799))

src/Compiler/Checking/TailCallChecks.fs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,7 @@ let CheckModuleBinding cenv (isRec: bool) (TBind _ as bind) =
792792
// warn for recursive calls in TryWith/TryFinally operations
793793
exprs |> Seq.iter (checkTailCall true)
794794
| Expr.Op(args = exprs) -> exprs |> Seq.iter (checkTailCall insideSubBindingOrTry)
795+
| Expr.Sequential(expr2 = expr2) -> checkTailCall insideSubBindingOrTry expr2
795796
| _ -> ()
796797

797798
checkTailCall false bodyExpr

tests/FSharp.Compiler.ComponentTests/ErrorMessages/TailCallAttribute.fs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,34 @@ namespace N
473473
"The member or function 'f' has the 'TailCallAttribute' attribute, but is not being used in a tail recursive way." }
474474
]
475475

476+
[<FSharp.Test.FactForNETCOREAPP>]
477+
let ``Warn for rec call in Sequential in use scope`` () =
478+
"""
479+
namespace N
480+
481+
module M =
482+
483+
[<TailCall>]
484+
let rec f () =
485+
let path = System.IO.Path.GetTempFileName()
486+
use file = System.IO.File.Open(path, System.IO.FileMode.Open)
487+
printfn "Hi!"
488+
f ()
489+
"""
490+
|> FSharp
491+
|> withLangVersion80
492+
|> compile
493+
|> shouldFail
494+
|> withResults [
495+
{ Error = Warning 3569
496+
Range = { StartLine = 11
497+
StartColumn = 13
498+
EndLine = 11
499+
EndColumn = 14 }
500+
Message =
501+
"The member or function 'f' has the 'TailCallAttribute' attribute, but is not being used in a tail recursive way." }
502+
]
503+
476504
[<FSharp.Test.FactForNETCOREAPP>]
477505
let ``Warn for invalid tailcalls in async expression`` () =
478506
"""

0 commit comments

Comments
 (0)