From eef1b2971379296f80c457f79faac371943cfc5f Mon Sep 17 00:00:00 2001 From: Matt Date: Sun, 20 Aug 2017 20:28:56 +0100 Subject: [PATCH] Don't suggest eta reduction if lambda arg is part of a tuple --- src/FSharpLint.Core/Rules/FunctionReimplementation.fs | 2 +- .../Rules/TestFunctionReimplementationRules.fs | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/FSharpLint.Core/Rules/FunctionReimplementation.fs b/src/FSharpLint.Core/Rules/FunctionReimplementation.fs index 77b677a47..22c05bfd2 100644 --- a/src/FSharpLint.Core/Rules/FunctionReimplementation.fs +++ b/src/FSharpLint.Core/Rules/FunctionReimplementation.fs @@ -27,7 +27,7 @@ module FunctionReimplementation = simplePatternsLength simplePatterns let rec private getLambdaParamIdent = function - | SynSimplePats.SimplePats(pattern::_, _) -> + | SynSimplePats.SimplePats([pattern], _) -> let rec getIdent = function | SynSimplePat.Id(ident, _, _, _, _, _) -> ident | SynSimplePat.Typed(simplePattern, _, _) diff --git a/tests/FSharpLint.Core.Tests/Rules/TestFunctionReimplementationRules.fs b/tests/FSharpLint.Core.Tests/Rules/TestFunctionReimplementationRules.fs index c54a6a7f0..e27ab337d 100644 --- a/tests/FSharpLint.Core.Tests/Rules/TestFunctionReimplementationRules.fs +++ b/tests/FSharpLint.Core.Tests/Rules/TestFunctionReimplementationRules.fs @@ -43,6 +43,17 @@ let f = fun a b -> a * b this.ErrorMsg.Contains "`( * )`" |> Assert.IsTrue + /// Regression test for https://github.com/fsprojects/FSharpLint/issues/237 + [] + member this.``When there's a tuple pattern in the lambda eta contraction should not be recommended.``() = + this.Parse """ +module Program + +let f = List.map (fun (x,_) -> id x) [] +""" + + this.AssertNoWarnings() + [] member this.``Quickfix for lambda reimplementing operator is to replace the lambda with the operator.``() = let source = """