Repository: tweag/nickel (rust)

Issue:
Enum variants don't merge even if they were the same
**Describe the bug**
Enum variants don't merge even if they were the same.

**To Reproduce**
```
nickel> `A & `A
error: Non mergeable terms
  ┌─ repl-input-1:1:1
  │
1 │ `A & `A
  │ ^^---^^
  │ │    │
  │ │    with this expression
  │ merged here
  │ cannot merge this expression
```

**Expected behavior**
It should result in
```
`A
```

**Environment**
 - OS name + version: `Linux xps 5.10.89-1-MANJARO #1 SMP PREEMPT Wed Dec 29 18:09:17 UTC 2021 x86_64 GNU/Linux`
 - Version of the code: a48713d

**Additional context**
I came across the issue when I applied the same contract (which specifies default enum variant) twice, something like
```
let T = {a | <A, B> | default = `A } & {a = `A} in {} | #T | #T
```

Pull request description:
Merge enum variants properly
Resolves #590

Patch:
diff --git a/src/eval/merge.rs b/src/eval/merge.rs
index 231265e9..8c859da0 100644
--- a/src/eval/merge.rs
+++ b/src/eval/merge.rs
@@ -199,6 +199,26 @@ pub fn merge(
                 ))
             }
         }
+        (Term::Enum(i1), Term::Enum(i2)) => {
+            if i1 == i2 {
+                Ok(Closure::atomic_closure(RichTerm::new(
+                    Term::Enum(i1),
+                    pos_op.into_inherited(),
+                )))
+            } else {
+                Err(EvalError::MergeIncompatibleArgs(
+                    RichTerm {
+                        term: SharedTerm::new(Term::Enum(i1)),
+                        pos: pos1,
+                    },
+                    RichTerm {
+                        term: SharedTerm::new(Term::Enum(i2)),
+                        pos: pos2,
+                    },
+                    pos_op,
+                ))
+            }
+        }
         (Term::MetaValue(meta1), Term::MetaValue(meta2)) => {
             // For now, we blindly closurize things and copy environments in this section. A
             // careful analysis would make it possible to spare a few closurize operations and more


Test patch:
diff --git a/tests/pass/records.ncl b/tests/pass/records.ncl
index d43da72b..ae957a88 100644
--- a/tests/pass/records.ncl
+++ b/tests/pass/records.ncl
@@ -37,6 +37,9 @@ let Assert = fun l x => x || %blame% l in
   {a = {b = 1}} & {a = {c = true}}
     == {a = {b = 1, c = true}},
 
+  {a = `A, b = `B} & {a = `A, c = `C}
+    == {a = `A, b = `B, c = `C},
+
   // merge_complex
   let rec1 = {
       a = false,