yanghuan / CSharp.lua

The C# to Lua compiler
Other
1.23k stars 202 forks source link

Interface overloads fail to be disambiguated in generated Lua #494

Closed joelverhagen closed 9 months ago

joelverhagen commented 9 months ago

Class overloads work fine (with Bar1). Call site works fine in both cases.

using System;

namespace FooBar;

public static class Program
{
    public static void Main()
    {
        IFoo<int> foo = new Foo<int>();
        foo.Bar();
        foo.Bar(1);
    }
}

public interface IFoo<T>
{
    void Bar();
    void Bar(int baz);
}

public class Foo<T> : IFoo<T>
{
    public void Bar()
    {
        Console.WriteLine("Bar");
    }

    public void Bar(int baz)
    {
        Console.WriteLine("Bar int " + baz);
    }
}

Generated Lua:


-- Generated by CSharp.lua Compiler
do
local System = System
local FooBar
local Foo_1Int32
System.import(function (out)
  FooBar = out.FooBar
  Foo_1Int32 = FooBar.Foo_1(System.Int32)
end)
System.namespace("FooBar", function (namespace)
  namespace.class("Program", function (namespace)
    local Main
    Main = function ()
      local foo = Foo_1Int32()
      foo:Bar()
      foo:Bar1(1)
    end
    return {
      Main = Main
    }
  end)

  namespace.interface("IFoo_1", function ()
    return function (T)
      return {}
    end
  end)

  namespace.class("Foo_1", function (namespace)
    return function (T)
      local Bar, Bar
      Bar = function (this)
        System.Console.WriteLine("Bar")
      end
      Bar = function (this, baz)
        System.Console.WriteLine("Bar int " .. baz)
      end
      return {
        base = function (out)
          return {
            out.FooBar.IFoo_1(T)
          }
        end,
        Bar = Bar, -- 2 "Bar" implementations instead of a Bar1
        Bar = Bar
      }
    end
  end)
end)

end
System.init({
  types = {
    "FooBar.IFoo_1",
    "FooBar.Foo_1",
    "FooBar.Program"
  }
})

FooBar.Program.Main()
joelverhagen commented 9 months ago

This can be easily worked around by giving the interface overload a new method name such as BarInt(int bar)