From 86c56fc95619e7c1d9314a4b0ef8db9c9a0bc2f9 Mon Sep 17 00:00:00 2001 From: webwarrior Date: Tue, 26 Dec 2023 11:52:40 +0100 Subject: [PATCH] Core.Tests: add NoPartialFunctions regression test Added regression test for NoPartialFunctions for case when `Value` instance method is called on non value that is not Option, but another Option value exists in scope. --- .../Rules/Conventions/NoPartialFunctions.fs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/FSharpLint.Core.Tests/Rules/Conventions/NoPartialFunctions.fs b/tests/FSharpLint.Core.Tests/Rules/Conventions/NoPartialFunctions.fs index dc9264f39..256a82eb3 100644 --- a/tests/FSharpLint.Core.Tests/Rules/Conventions/NoPartialFunctions.fs +++ b/tests/FSharpLint.Core.Tests/Rules/Conventions/NoPartialFunctions.fs @@ -62,6 +62,19 @@ module Program = Assert.IsTrue(this.ErrorExistsAt(7, 34)) this.AssertErrorWithMessageExists("Consider using pattern matching instead of partial function/method 'Option.Value'.") + [] + member this.``No error for calling Value on ref type (regression)``() = + this.Parse(""" +namespace Foo +module Program = + let foo = None + let bar = ref 0 + + let printFoo() = + System.Console.WriteLine (bar.Value.ToString())""") + + Assert.IsTrue this.NoErrorsExist + [] member this.``Error for Option.Value (List.tryHead test case)``() = this.Parse("""