From 98aee72eb3dc40b622d647392496ac4cd76945e9 Mon Sep 17 00:00:00 2001 From: webwarrior-ws Date: Tue, 7 Jul 2026 11:12:54 +0200 Subject: [PATCH 1/2] NoPartialFunctions: test for Seq.cast Added test that makes sure that using `Seq.cast` leads to a warning suggesting using `Seq.choose tryUnbox` instead. --- .../Rules/Conventions/NoPartialFunctions.fs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/FSharpLint.Core.Tests/Rules/Conventions/NoPartialFunctions.fs b/tests/FSharpLint.Core.Tests/Rules/Conventions/NoPartialFunctions.fs index 56ac73d97..4052acec9 100644 --- a/tests/FSharpLint.Core.Tests/Rules/Conventions/NoPartialFunctions.fs +++ b/tests/FSharpLint.Core.Tests/Rules/Conventions/NoPartialFunctions.fs @@ -171,6 +171,16 @@ if foo.Head 1 then Assert.IsTrue this.ErrorsExist this.AssertErrorWithMessageExists("Consider using 'List.tryHead' instead of partial function/method 'List.Head'.") + [] + member this.``Error for Seq.cast``() = + this.Parse """ +let foo = [ box "Hello"; box 42 ] +let bar = Seq.cast foo +""" + + Assert.IsTrue this.ErrorsExist + this.AssertErrorWithMessageExists("Consider using 'Seq.choose tryUnbox' instead of partial function/method 'Seq.cast'.") + [] member this.``Regression found when parsing Console/Program_fs``() = this.Parse """ From bd45fdc50a4c15f11967dec1dbed241aeb58d0c5 Mon Sep 17 00:00:00 2001 From: webwarrior-ws Date: Tue, 7 Jul 2026 11:15:23 +0200 Subject: [PATCH 2/2] NoPartialFunctions: added Seq.cast To list of partial function identifiers, because Seq.cast will raise an exception at runtime if one of the elements can't be cast to specified type. --- src/FSharpLint.Core/Rules/Conventions/NoPartialFunctions.fs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/FSharpLint.Core/Rules/Conventions/NoPartialFunctions.fs b/src/FSharpLint.Core/Rules/Conventions/NoPartialFunctions.fs index 5460f5133..013bc43ab 100644 --- a/src/FSharpLint.Core/Rules/Conventions/NoPartialFunctions.fs +++ b/src/FSharpLint.Core/Rules/Conventions/NoPartialFunctions.fs @@ -57,6 +57,7 @@ let private partialFunctionIdentifiers = ("Seq.reduce", Function "Seq.fold") ("Seq.reduceBack", Function "Seq.foldBack") ("Seq.pick", Function "Seq.tryPick") + ("Seq.cast", Function "Seq.choose tryUnbox") // List ("List.exactlyOne", Function "List.tryExactlyOne")