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

Incorrect method overload with objects array #287

Open
DevCorvette opened this issue Apr 5, 2023 · 4 comments
Open

Incorrect method overload with objects array #287

DevCorvette opened this issue Apr 5, 2023 · 4 comments

Comments

@DevCorvette
Copy link

When I run this code:

using NiL.JS.Core;
using NiL.JS.Core.Interop;

var script = @"
console.log('str: ', container.test('str'));
console.log('1: ', container.test(1));
console.log('1.1: ', container.test(1.1));
console.log('[1, 2]: ', container.test([1, 2]));
";

var context = new Context();
context.DefineConstant("container", new FunctionContainer());
context.Eval(script);

class FunctionContainer : CustomType
{
    public string test(string s)
    {
        return $"it is string {s}";
    }

    public string test(long l)
    {
        return $"it is long {l}";
    }

    public string test(double d)
    {
        return $"it is double {d}";
    }

    public string test(long[] array)
    {
       return $"it is long[] {String.Join(", ", array)}";
    }
}

I got wrong result for array:

str: it is string str
1: it is long 1
1.1: it is double 1,1
[1, 2]: it is long 0

Is it bug?

@nilproject
Copy link
Owner

Yes, it's bug

@DevCorvette
Copy link
Author

Can you please fix it soon?

@nilproject
Copy link
Owner

So, i tried to fix this, but i couldn't. There are a lot of corner cases. As a workaround you can move method with array in top of class definition. Or replace long[] with JSValue[].
Maybe sometimes i can come up with a solution to this problem

@DevCorvette
Copy link
Author

Thank you! It works!

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

No branches or pull requests

2 participants