Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing [<TailCall>] warning in list comprehension #16652

Merged
merged 4 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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." }
]
Loading