fsprojects / fsprojects/FSharpLint

(FL0034): ReimplementsFunction shown error, but after implementing suggestion build fails

Open
#424 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
F#
Stars
327
Forks
74
PR merge metrics
No merged PRs in 30d

Description

Description

Please provide a succinct description of your issue.
I have a C# class with constructor accepting Func... as parameter.
Creation of object in F# and using applied function as argument gives Lint error, but after fixing it based on suggestion code does not compile.
In order to compile I need to instantiate instance of Func
So, the question is: Is it really more preferable way of writing?
FuncClass(fun str -> myLocalFunc str) - compile but Lint is angry
FuncClass(myLocalFunc) - do not compile
FuncClass(Func<_,_>(myLocalFunc)) - compile

Repro steps
  1. Have C# class:
public class FuncClass
    {
        public FuncClass(Func<string, string> func)
        {
            Func = func;
        }

        public Func<string, string> Func { get; }
    }
  1. Have local function as string -> string:
    let myLocalFunc str = sprintf "%s" str
  2. Create instance:
let createNotComplientClass () =
    FuncClass(fun str -> myLocalFunc str)
Expected behavior

Probably it is OK to have re-implemented function here

Actual behavior

Lint gives error, but suggested fix do not compile

Known workarounds

This do not give Lint issue, and compile. But is it best F# approach?

let createComplientClass () =
    FuncClass(Func<_,_>(myLocalFunc))

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce FL0034 with the provided C# FuncClass and F# function examples, then inspect the lint rule that reports the reimplemented function. Check the suggested rewrite against the compilation failure and the Func<_ , _> workaround; done means the diagnostic and fix agree with valid F#/.NET interop.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, fsharp
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.