Skip to content

NoPartialFunctions: fixed bug on object expressions#864

Merged
knocte merged 2 commits into
fsprojects:masterfrom
webwarrior-ws:object-expr-bug
Jul 7, 2026
Merged

NoPartialFunctions: fixed bug on object expressions#864
knocte merged 2 commits into
fsprojects:masterfrom
webwarrior-ws:object-expr-bug

Conversation

@webwarrior-ws

Copy link
Copy Markdown
Contributor

By removing incorrect type cast.

Also added a regression test.

Added a regression test for code that includes object
expression.
By removing incorrect type cast.
@knocte knocte merged commit 9aa060d into fsprojects:master Jul 7, 2026
8 checks passed
@knocte

knocte commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

@webwarrior-ws just realised, Seq.cast is a partial function! So NoPartialFunctions should have detected this at SelfCheck, please cook a PR that catches Seq.cast and suggests Seq.choose because Seq.tryCast doesn't exist yet.

E.g.:

// 1. Define the tryCast helper function
let tryCast<'T> (item: obj) =
    match item with
    | :? 'T as casted -> Some casted
    | _ -> None

// 2. Use it with Seq.choose to filter and cast elements
let mixedCollection = [ box "Hello"; box 42; box "World"; box 3.14 ]

let stringsOnly =
    mixedCollection
    | > Seq.choose tryCast<string>

// stringsOnly now contains: seq ["Hello"; "World"]

Then after that cook a PR for https://github.com/fsprojects/FSharpx.Collections to add Seq.tryCast there, and when that gets merged and released, we can change the recommendation in FSharpLint from Seq.choose to FSharpx.Collections.Seq.tryCast

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants