Skip to content
This repository has been archived by the owner on Nov 22, 2023. It is now read-only.

Fix Equal() and GetHashCode() #332

Merged
merged 3 commits into from
Jun 15, 2020
Merged

Fix Equal() and GetHashCode() #332

merged 3 commits into from
Jun 15, 2020

Conversation

erikzhang
Copy link
Member

Closes #330

@erikzhang erikzhang requested a review from shargon June 5, 2020 07:41
@erikzhang
Copy link
Member Author

@ixje Please check this.

src/neo-vm/Types/StackItem.cs Show resolved Hide resolved
src/neo-vm/Types/InteropInterface.cs Show resolved Hide resolved
src/neo-vm/Types/ByteString.cs Show resolved Hide resolved
@ixje
Copy link
Contributor

ixje commented Jun 5, 2020 via email

Comment on lines -43 to -46
public override bool Equals(object obj)
{
return this == obj;
}
Copy link
Contributor

@ixje ixje Jun 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of deleting should we do reference + sequence equality checking (=the same as ByteString)? Now it is only reference equality checked via StackItem.

I can imagine a use-case where you dynamically build 2 Buffers, then compare if they're equal (e.g. for some validation scheme). In order to do that you would have to convert them to ByteStrings first or the results will be false.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shargon What do you think?

Copy link
Member Author

@erikzhang erikzhang Jun 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are temporarily unable to reach a consensus on this issue, and the function here has not been modified, it is still the same as the original. So I will merge this PR first. If there is a problem, you can create a new issue separately. @ixje

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is @shargon afk or did he share his opinion elsewhere?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry i miss this conversation.

reference + sequence equality checking

If it's the same reference, the sequence will be the same, but reference it's good for me

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shargon The point I'm trying to make is that the immutable version (ByteString) does reference + sequence checking, but the mutable version Buffer does not. Which I think should be the same, and you previous

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could be easier, incompatible with c# but easy for developers. Use == and check if the buffer it's the same. But also... do you want to be able to compare ByteString with Buffer?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as described above I can imagine a case where you'd like to compare 2 Buffers on sequence without having to convert them to ByteString first. It doesn't sound logical to me that that sequence comparison only works in the immutable variant.

return hash;
}
}

public override bool ToBoolean()
{
return true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return true;
if (Size > Integer.MaxSize) return true;
return Unsafe.NotZero(InnerBuffer);

same logic as applied for ByteString.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are temporarily unable to reach a consensus on this issue, and the function here has not been modified, it is still the same as the original. So I will merge this PR first. If there is a problem, you can create a new issue separately. @ixje

@erikzhang erikzhang merged commit 01d6776 into master Jun 15, 2020
@erikzhang erikzhang deleted the fixes/equal-gethashcode branch June 15, 2020 06:16
@shargon shargon mentioned this pull request Jun 17, 2020
@ProDog
Copy link

ProDog commented Jun 18, 2020

Please fix this 😀
https://github.com/neo-project/neo/blob/master/src/neo/SmartContract/ContainerPlaceholder.cs#L17

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Primitive type comparison failure
4 participants