Skip to content

Commit 2e021f5

Browse files
authored
Fix missing [<TailCall>] warning in list comprehension (#16652)
* 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
1 parent 0de949c commit 2e021f5

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

docs/release-notes/.FSharp.Compiler.Service/8.0.300.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 warning for recursive calls in list comprehensions. ([PR #16652](https://github.com/dotnet/fsharp/pull/16652))
34
* 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))
45
* `nameof Module` expressions and patterns are processed to link files in `--test:GraphBasedChecking`. ([PR #16550](https://github.com/dotnet/fsharp/pull/16550))
56
* 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))

src/Compiler/Checking/TailCallChecks.fs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -539,12 +539,10 @@ and CheckExprOp cenv (op, tyargs, args, m) ctxt : unit =
539539
| TOp.ValFieldSet _rf, _, [ _arg1; _arg2 ] -> ()
540540

541541
| TOp.Coerce, [ tgtTy; srcTy ], [ x ] ->
542-
let tailCall = TailCall.YesFromExpr cenv.g x
543-
544542
if TypeDefinitelySubsumesTypeNoCoercion 0 g cenv.amap m tgtTy srcTy then
545-
CheckExpr cenv x ctxt tailCall
543+
CheckExpr cenv x ctxt TailCall.No
546544
else
547-
CheckExprNoByrefs cenv tailCall x
545+
CheckExprNoByrefs cenv TailCall.No x
548546

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

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,3 +1512,29 @@ module Microsoft.FSharp.Core
15121512
Message =
15131513
"The member or function 'f' has the 'TailCallAttribute' attribute, but is not being used in a tail recursive way." }
15141514
]
1515+
1516+
[<FSharp.Test.FactForNETCOREAPP>]
1517+
let ``Warn for recursive call in list comprehension`` () =
1518+
"""
1519+
namespace N
1520+
1521+
module M =
1522+
1523+
[<TailCall>]
1524+
let rec reverse (input: list<'t>) =
1525+
match input with
1526+
| head :: tail -> [ yield! reverse tail; head ]
1527+
| [] -> []
1528+
"""
1529+
|> FSharp
1530+
|> compile
1531+
|> shouldFail
1532+
|> withResults [
1533+
{ Error = Warning 3569
1534+
Range = { StartLine = 9
1535+
StartColumn = 40
1536+
EndLine = 9
1537+
EndColumn = 52 }
1538+
Message =
1539+
"The member or function 'reverse' has the 'TailCallAttribute' attribute, but is not being used in a tail recursive way." }
1540+
]

0 commit comments

Comments
 (0)