Struct not found in dictionary and array

Using Fire .2485.

If I create a struct, add it to an array or set it as a dictionary key, and then try to find it in the array using indexOf() or get a dictionary value using struct as a key, like guard let someValue = dict[someStructAsKey], it’s never found, meaning that for array indexOf() returns -1, and for dictionary guard let returns nil.

It works for array if I override func equals(), so I assume I would have to override hashValue / hashCode() to use dictionary?

AFAIK in Java structs are also compared by pointer ref, same as classes? So, can this even be solved on a compiler level to be more swift-like, or is overriding equals() and hashValue / hashCode() the only way to go?

From what I could figure out looking at the source of swift base library on RO github, Equatable and Comparable are just stubs, right?

Test project attached. (144.7 KB)

Just figured out how to override hashCode() and tested my own test app. Writing an extension of a struct that overrides both, equals() and hashCode() works for both array and dictionary.

So the only question remains if this can be done by the compiler.

Current. In order to find the right item, the dictionary has to compare the ting you are looking for with the keys it has stored. Since structs/records are not heap based, what you pass in is a unique separate value from the one stored as key, ben though the data might match. So the dictionary has no way to determine equality, unless you implement it.

Java doesn’t have structs.

Do you think this will (ever) be possible in Silver using Comparable and Equatable? Sometime in the future maybe? Or is something like that simply too complicated to implement in Java or .NET? Especially as there is no operator overloading in Java (I think).