Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interop with C# method with optional argument and params #1120

Closed
lucasteles opened this issue Feb 20, 2022 · 4 comments · Fixed by dotnet/fsharp#16688
Closed

Interop with C# method with optional argument and params #1120

lucasteles opened this issue Feb 20, 2022 · 4 comments · Fixed by dotnet/fsharp#16688

Comments

@lucasteles
Copy link

lucasteles commented Feb 20, 2022

This case happened to me when I was using FluentAssertions, when I try to call a C# method that receives the first argument with a default value and a second params argument I can't omit both parameters.

E.g:

    public class Class1
    {
        public static string Foo(string something = "", params object[] args) => 
            string.Format(something, args);
    }

If I try to use this method in F# I expected to be able to call it in this way:

 let result1 = Class1.Foo()

But this gives me an error :

Error FS0501: 
The member or object constructor 'Foo' takes 2 argument(s) but is here given 0. 
The required signature is 'Class1.Foo(?something: string, [<System.ParamArray>] args: obj[]) : string'.

So, to make it work I need to pass the first argument explicitly which I would expect to be optional :

 let result1 = Class1.Foo("")

Pros and Cons

I don't know if this is bt design, but is very confusing and made the interop harder and noisy in some cases.

For Readers

If you would like to see this issue implemented, please click the 👍 emoji on this issue. These counts are used to generally order the suggestions by engagement.

@baronfel
Copy link
Contributor

This may have been addressed in dotnet/fsharp#12515 - where default arguments were being factored into the logic. It's worth testing though.

@dsyme
Copy link
Collaborator

dsyme commented Apr 13, 2023

I checked - this hasn't been addressed

@edgarfgp
Copy link
Member

edgarfgp commented Aug 7, 2024

Consider closing this as has been implemented by dotnet/fsharp#16688

@vzarytovskii
Copy link

Consider closing this as has been implemented by dotnet/fsharp#16688

Good catch, thanks, Edgar!

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

Successfully merging a pull request may close this issue.

5 participants