Skip to content

Commit

Permalink
Implement missing equality on ADTs (enum variants)
Browse files Browse the repository at this point in the history
Implement the missing case of the `==` operator for newly introduced
ADTs (enum variants), together with basic tests.

Co-authored-by: jneem <joeneeman@gmail.com>
  • Loading branch information
yannham and jneem committed Jan 30, 2024
1 parent bbc56d0 commit 834f285
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
7 changes: 6 additions & 1 deletion core/src/eval/operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3126,7 +3126,12 @@ fn eq<C: Cache>(
(Term::Str(s1), Term::Str(s2)) => Ok(EqResult::Bool(s1 == s2)),
(Term::Lbl(l1), Term::Lbl(l2)) => Ok(EqResult::Bool(l1 == l2)),
(Term::SealingKey(s1), Term::SealingKey(s2)) => Ok(EqResult::Bool(s1 == s2)),
(Term::Enum(id1), Term::Enum(id2)) => Ok(EqResult::Bool(id1 == id2)),
(Term::Enum(id1), Term::Enum(id2)) => Ok(EqResult::Bool(id1.ident() == id2.ident())),
(Term::EnumVariant(id1, arg1), Term::EnumVariant(id2, arg2))
if id1.ident() == id2.ident() =>
{
Ok(gen_eqs(cache, std::iter::once((arg1, arg2)), env1, env2))
}
(Term::Record(r1), Term::Record(r2)) => {
let merge::split::SplitResult {
left,
Expand Down
6 changes: 6 additions & 0 deletions core/tests/integration/pass/core/eq.ncl
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,11 @@ let {check, ..} = import "../lib/assert.ncl" in
[[1,2,3,4], [1,2,3,4], [1,2,3,4], [1,2,3,4]]
== false
),

# ADTs
'Left..(1+1) == 'Left..(2),
'Left..(1) != 'Left..(2),
'Left..(2) != 'Right..(2),
'Up..([1,2,3]) == 'Up..([0+1,1+1,2+1]),
]
|> check

0 comments on commit 834f285

Please sign in to comment.