nilproject / NiL.JS

JavaScript engine for .NET written in C#.
BSD 3-Clause "New" or "Revised" License
332 stars 46 forks source link

Incorrect method overload with objects array #287

Open DevCorvette opened 1 year ago

DevCorvette commented 1 year ago

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 commented 1 year ago

Yes, it's bug

DevCorvette commented 1 year ago

Can you please fix it soon?

nilproject commented 1 year ago

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 commented 1 year ago

Thank you! It works!