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

A few more Eq fixes #340

Merged
merged 3 commits into from
Aug 3, 2023
Merged

A few more Eq fixes #340

merged 3 commits into from
Aug 3, 2023

Conversation

acl-cqc
Copy link
Contributor

@acl-cqc acl-cqc commented Aug 3, 2023

  • HashableValue's are Eq, that's the whole point of them ;-)
  • ContainerValue's can also be Eq if they contain things that are
  • CustomSerialized probably should not be
  • But, provide missing impl of equal_const

@acl-cqc acl-cqc requested a review from ss2165 August 3, 2023 09:10
@@ -444,5 +450,7 @@ mod test {
let t: SimpleType = typ_float.clone().into();
assert_matches!(val.check_type(&t.try_into().unwrap()),
Err(ConstTypeError::CustomCheckFail(CustomCheckFail::TypeMismatch(a, b))) => a == typ_int && b == typ_float);

assert_eq!(val, val);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this was failing before, because equality of Box<dyn CustomConst> does not fall back to PartialEq....

src/values.rs Outdated
@@ -16,7 +16,7 @@ use crate::{

/// A constant value/instance of a [HashableType]. Note there is no
/// equivalent of [HashableType::Variable]; we can't have instances of that.
#[derive(Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize)]
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
Copy link
Member

Choose a reason for hiding this comment

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

should it derive Hash as well?

src/values.rs Outdated
@@ -108,6 +108,8 @@ pub enum ContainerValue<T> {
Sum(usize, Box<T>), // Tag and value
}

impl<Elem: Eq> Eq for ContainerValue<Elem> {}
Copy link
Member

Choose a reason for hiding this comment

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

👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In fact we can just #[derive(Eq)] - the derive macro is smart enough to condition the generated impl on the appropriate condition of the arguments, which is pretty neat.

@acl-cqc acl-cqc added this pull request to the merge queue Aug 3, 2023
Merged via the queue into main with commit c77e661 Aug 3, 2023
5 checks passed
@acl-cqc acl-cqc deleted the more-eq-fixes branch August 3, 2023 10:01
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

Successfully merging this pull request may close these issues.

2 participants