Skip to content

Commit

Permalink
Fix missing [<TailCall>] warning in list comprehension (#16652)
Browse files Browse the repository at this point in the history
* Add test for recursive call in list comprehension

* Change the default to TailCall.No when checking the args of a Coerce

* add release-notes entry

* add PR number to release notes
  • Loading branch information
dawedawe authored Feb 7, 2024
1 parent 0de949c commit 2e021f5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
1 change: 1 addition & 0 deletions docs/release-notes/.FSharp.Compiler.Service/8.0.300.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
### Fixed

* Fix missing warning for recursive calls in list comprehensions. ([PR #16652](https://github.com/dotnet/fsharp/pull/16652))
* Code generated files with > 64K methods and generated symbols crash when loaded. Use infered sequence points for debugging. ([Issue #16399](https://github.com/dotnet/fsharp/issues/16399), [#PR 16514](https://github.com/dotnet/fsharp/pull/16514))
* `nameof Module` expressions and patterns are processed to link files in `--test:GraphBasedChecking`. ([PR #16550](https://github.com/dotnet/fsharp/pull/16550))
* Graph Based Checking doesn't throw on invalid parsed input so it can be used for IDE scenarios ([PR #16575](https://github.com/dotnet/fsharp/pull/16575), [PR #16588](https://github.com/dotnet/fsharp/pull/16588), [PR #16643](https://github.com/dotnet/fsharp/pull/16643))
Expand Down
6 changes: 2 additions & 4 deletions src/Compiler/Checking/TailCallChecks.fs
Original file line number Diff line number Diff line change
Expand Up @@ -539,12 +539,10 @@ and CheckExprOp cenv (op, tyargs, args, m) ctxt : unit =
| TOp.ValFieldSet _rf, _, [ _arg1; _arg2 ] -> ()

| TOp.Coerce, [ tgtTy; srcTy ], [ x ] ->
let tailCall = TailCall.YesFromExpr cenv.g x

if TypeDefinitelySubsumesTypeNoCoercion 0 g cenv.amap m tgtTy srcTy then
CheckExpr cenv x ctxt tailCall
CheckExpr cenv x ctxt TailCall.No
else
CheckExprNoByrefs cenv tailCall x
CheckExprNoByrefs cenv TailCall.No x

| TOp.Reraise, [ _ty1 ], [] -> ()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1512,3 +1512,29 @@ module Microsoft.FSharp.Core
Message =
"The member or function 'f' has the 'TailCallAttribute' attribute, but is not being used in a tail recursive way." }
]

[<FSharp.Test.FactForNETCOREAPP>]
let ``Warn for recursive call in list comprehension`` () =
"""
namespace N
module M =
[<TailCall>]
let rec reverse (input: list<'t>) =
match input with
| head :: tail -> [ yield! reverse tail; head ]
| [] -> []
"""
|> FSharp
|> compile
|> shouldFail
|> withResults [
{ Error = Warning 3569
Range = { StartLine = 9
StartColumn = 40
EndLine = 9
EndColumn = 52 }
Message =
"The member or function 'reverse' has the 'TailCallAttribute' attribute, but is not being used in a tail recursive way." }
]

0 comments on commit 2e021f5

Please sign in to comment.