From 4ae8354d290f34cfa9b4ae78375c055b54e03b64 Mon Sep 17 00:00:00 2001 From: webwarrior-ws Date: Thu, 2 Jul 2026 15:32:46 +0200 Subject: [PATCH 1/2] NoPartialFunctions: regression test for obj. expr Added a regression test for code that includes object expression. --- .../Rules/Conventions/NoPartialFunctions.fs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/FSharpLint.Core.Tests/Rules/Conventions/NoPartialFunctions.fs b/tests/FSharpLint.Core.Tests/Rules/Conventions/NoPartialFunctions.fs index dc75b38f5..56ac73d97 100644 --- a/tests/FSharpLint.Core.Tests/Rules/Conventions/NoPartialFunctions.fs +++ b/tests/FSharpLint.Core.Tests/Rules/Conventions/NoPartialFunctions.fs @@ -182,6 +182,24 @@ module Program = """ this.AssertNoWarnings() + + [] + member this.``Regression test for object expressions``() = + this.Parse """ +type Foo = + abstract Bar: unit -> unit + +let host = + { new Foo with + member _.Bar() = + () } + +let x = + JsonDocument.Parse(responseBody).RootElement |> ignore + Option.ofObj(host).Value +""" + + Assert.IsTrue this.ErrorsExist (* // Examples for future additions, see 'Foo.Bar.Baz' in partialInstanceMemberIdentifiers in .Core/.../NoPartialFunctions.fs From 93e69692563adbde704193604012dc45c1856c1a Mon Sep 17 00:00:00 2001 From: webwarrior-ws Date: Thu, 2 Jul 2026 14:31:01 +0200 Subject: [PATCH 2/2] NoPartialFunctions: fix bug on object expressions By removing incorrect type cast. --- src/FSharpLint.Core/Rules/Conventions/NoPartialFunctions.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/FSharpLint.Core/Rules/Conventions/NoPartialFunctions.fs b/src/FSharpLint.Core/Rules/Conventions/NoPartialFunctions.fs index 4834886f4..5460f5133 100644 --- a/src/FSharpLint.Core/Rules/Conventions/NoPartialFunctions.fs +++ b/src/FSharpLint.Core/Rules/Conventions/NoPartialFunctions.fs @@ -173,7 +173,7 @@ let rec private tryFindTypedExpression (range: Range) (expressions: List List.collect (fun (_, imlps) -> imlps) let exprs = List.append overrides interfaceImlps - |> Seq.cast + |> Seq.map (fun expr -> expr.Body) |> Seq.toList tryFindTypedExpression range (baseCallExpr :: exprs @ rest) | FSharpExprPatterns.TraitCall(_sourceTypes, _traitName, _typeArgs, _typeInstantiation, _argTypes, argExprs) :: rest ->