yanghuan / CSharp.lua

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

Switch on value tuple fails to match due to unassigned destructuring #479

Closed joelverhagen closed 10 months ago

joelverhagen commented 10 months ago

Repro:

internal class Program
{
    private static void Main()
    {
        (int X, int Y) a = (1, 2);
        switch (a)
        {
            case (1, 2):
                Console.WriteLine("match");
                break;
            default:
                Console.WriteLine("no match");
                break;
        }
    }
}

Generated Lua:


-- Generated by CSharp.lua Compiler
do
local System = System
System.namespace("", function (namespace)
  namespace.class("Program", function (namespace)
    local Main
    Main = function ()
      local a = System.ValueTuple(1, 2)
      repeat
        local default = a
        if extern == 1 and extern == 2 then -- extern is never set
          System.Console.WriteLine("match")
          break
        else
          System.Console.WriteLine("no match")
          break
        end
      until 1
    end
    return {
      Main = Main
    }
  end)
end)

end
System.init({
  types = {
    "Program"
  }
})

Program.Main()
joelverhagen commented 10 months ago

A workaround is to use if / else.