-
Notifications
You must be signed in to change notification settings - Fork 9
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
Compound, List, and Array Tags give false-positives when using == #31
Comments
Currently compound tags only compare the name of the tag to determine equality, and do not check contents. The given example results in two tags where neither has a name, therefore are considered "equal" using that very generic comparison. While it would be somewhat trivial to implement, comparing dictionaries (i.e. compound tags) for equality is not going to be efficient (deep nesting, binary data, etc), and rarely ever useful or meaningful beyond these simple examples. While I am not outright opposed to implementing it, I am leaning strongly in favor of not doing so, as Linq and/or existing extension methods ( I am open-minded to arguments to the contrary, but it should be noted that comparing table/dictionary types for equality is a "code smell" in pretty much any language, including C#. Typically you would want to be checking for known/expected keys, and handling them as-needed to validate the data. I will consider a compromised "middle-ground" solution, where compound tags compare equality of their names, number of items, and perhaps check if all child key names are the same, but a full recursive comparison of child-types and their equality is going to require some powerful persuasion. |
I think that reasoning is sound, but if not implementing a full equality check, I would favour not having one at all. A prime example of that is how I discovered this issue: I was comparing a list of compounds against a mask (a small mask) and suddenly found that it just matched the first one it finds. I dug into the code to figure out why and thus this issue was born. An innocent programmer will assume that a I needed equality checking, but it wasn't too hard to implement myself. Maybe having an additional method like As it goes for code I think the best implementation would be removing the |
(Note that even having a |
I do agree with this. The default equality for compound tags should only be |
Adjusted the title to better fit the current topic. As is apparent from the title this issue affects |
I intended to address this part of your comment in my previous reply, but yes, I agree this sensible and more in line with language conventions. The only part of I dislike about this approach is that it loses the ability to check for equality of tags without first casting or pattern-matching a |
That makes perfect sense, I like that |
I came back to this because my inbox failed to mark this as read. I noticed you said
I think the only issue here is that you would need to cast to |
@Fisch37 Assuming each tag shared a common interface that implemented It also may bring up some new issues with what is considered "equal" and the rules for type coercion. For example, assume we have three long a = 1L;
int b = 1;
float c = 1.0f;
bool IsTrue = (a == b && b == c); Realistically, finding a tag with a specific value is not commonly needed, and the typical use-case is finding a tag with a certain name then doing something with its value, so this "sacrifice" will be of little consequence. |
When comparing compound tags the bar for equality is set extremely low. Two compound objects are equal if they have the same type (guaranteed) and their names are the same.
This is because the CompoundTag class does not override the Tag.Equals method leading to this bizarre behaviour. A very simple check is this:
This will pass even though the two compounds aren't remotely the same.
The text was updated successfully, but these errors were encountered: