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

Treat variants separately to fix their value_ptr_eq impl #215

Merged
merged 1 commit into from
Dec 10, 2020

Conversation

udoprog
Copy link
Collaborator

@udoprog udoprog commented Dec 10, 2020

This fixes comparisons of variants, so that variants of the same type (same enum) don't raise a type error, but rather are simply checked for equality.

That means that code like this:

enum Foo { A, B }

pub fn main() {
    assert_eq!(Foo::A, Foo::B);
}    

Used to result in:

  ┌─ scripts\test.rn:4:5
  │
4 │     assert_eq!(Foo::A, Foo::B);
  │     ^^^^^^^^^^^^^^^^^^^^^^^^^^ unsupported vm operation `Foo::A == Foo::B`

But now instead give:

  ┌─ scripts\test.rn:4:5
  │
4 │     assert_eq!(Foo::A, Foo::B);
  │     ^^^^^^^^^^^^^^^^^^^^^^^^^^ panicked: assertion failed (left == right):
left: Foo::A
right: Foo::B

It also means that we can now successfully compare different variants of the same enum with each other without raising an error:

enum Foo { A, B }

pub fn main() {
    assert!(Foo::A != Foo::B);
}    

@udoprog udoprog added the bug Something isn't working label Dec 10, 2020
@udoprog udoprog merged commit 8c50299 into main Dec 10, 2020
@udoprog udoprog deleted the better-variants branch December 10, 2020 13:19
@udoprog udoprog added the changelog Issue has been added to the changelog label Jan 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working changelog Issue has been added to the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant