yanghuan / CSharp.lua

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

Record types don't work correctly in dictionaries #509

Closed tomshackell closed 6 months ago

tomshackell commented 6 months ago

Consider the following example:

public class Program {
    public static void Main() {
        var dict = new Dictionary<Id, int>();
        dict.Add(new Id("Alice"), 42);
        var age = dict[new Id("Alice")];
        Console.WriteLine("Alice is " + age);
    }
}

record Id(string id);

In regular C# this prints Alice is 42, however, in CSharp.lua:

C:\Tools\lua-5.4.2_Win64_bin\lua.exe: System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
stack traceback:
        dist/out.lua:8016: in method 'get'
        dist/out.lua:19423: in field 'Main'
        dist/out.lua:20304: in main chunk
        [C]: in ?
make: *** [run] Error 1