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

KeyValuePair does not implement GetHashCode (error about "user-defined struct") #476

Closed
joelverhagen opened this issue Jan 4, 2024 · 1 comment

Comments

@joelverhagen
Copy link
Contributor

I think this is confusing because from the user's perspective (the user of CSharp.Lua) a KVP is not user-defined.

Repro:

internal class Program
{
    private static void Main(string[] args)
    {
        var dictA = new Dictionary<KeyValuePair<int, bool>, string>();
        dictA.Add(KeyValuePair.Create(1, true), "foo");
        var dictB = new Dictionary<KeyValuePair<int, bool>, string>();
        dictB.Add(KeyValuePair.Create(1, true), "baz");
        Console.WriteLine(dictA.Except(dictB).Count());
    }
}

Error:

C:\Users\jver\Downloads\lua-5.2.4_Win64_bin\lua52.exe: System.NotSupportedException: System.Collections.Generic.KeyValuePair`2[System.Collections.Generic.KeyValuePair`2[System.Int32,System.Boolean],System.String] User-defined struct not support GetHashCode
stack traceback:
        .\out.lua:10330: in function 'addToSet'
        .\out.lua:10444: in function 'init'
        .\out.lua:9783: in function 'MoveNext'
        .\out.lua:10839: in function 'Count'
        .\out.lua:19606: in function 'Main'
        .\out.lua:19621: in main chunk
        [C]: in function 'require'
        ...arp.lua\CSharp.lua.Launcher\bin\Debug\net7.0\DT\main.lua:1: in main chunk
        [C]: in ?
@joelverhagen
Copy link
Contributor Author

joelverhagen commented Jan 4, 2024

I started working on this and got struck on behavior I don't understand. Tuple returns a string representation of its content as the hash code. And some base types return non-integers as their hash code (#477).

joelverhagen added a commit to joelverhagen/FactorioTools that referenced this issue Jan 4, 2024
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

1 participant