Skip to content

Commit ba7f99e

Browse files
authored
Merge PR #865 from webwarrior-ws/seq-cast
NoPartialFunctions: add Seq.cast to list of partial function identifiers
2 parents 9aa060d + bd45fdc commit ba7f99e

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

src/FSharpLint.Core/Rules/Conventions/NoPartialFunctions.fs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ let private partialFunctionIdentifiers =
5757
("Seq.reduce", Function "Seq.fold")
5858
("Seq.reduceBack", Function "Seq.foldBack")
5959
("Seq.pick", Function "Seq.tryPick")
60+
("Seq.cast", Function "Seq.choose tryUnbox")
6061

6162
// List
6263
("List.exactlyOne", Function "List.tryExactlyOne")

tests/FSharpLint.Core.Tests/Rules/Conventions/NoPartialFunctions.fs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,16 @@ if foo.Head 1 then
171171
Assert.IsTrue this.ErrorsExist
172172
this.AssertErrorWithMessageExists("Consider using 'List.tryHead' instead of partial function/method 'List.Head'.")
173173

174+
[<Test>]
175+
member this.``Error for Seq.cast``() =
176+
this.Parse """
177+
let foo = [ box "Hello"; box 42 ]
178+
let bar = Seq.cast<string> foo
179+
"""
180+
181+
Assert.IsTrue this.ErrorsExist
182+
this.AssertErrorWithMessageExists("Consider using 'Seq.choose tryUnbox' instead of partial function/method 'Seq.cast'.")
183+
174184
[<Test>]
175185
member this.``Regression found when parsing Console/Program_fs``() =
176186
this.Parse """

0 commit comments

Comments
 (0)