E0006: duplicate_slot
E0006 duplicate_slot — two memory slots of one cell share a name.
A compile-time error of soma check, the checker of the Soma programming language (soma explain E0006).
The rule
Within one cell's memory, every slot needs its own name. Two slots named loans would share one name for two stores (here with two value types), so reads and writes could not say which one they mean. Give each slot a distinct name that says what it holds.
A program that triggers it
wrong.cell
cell Library {
memory {
loans: Map<String, String> [persistent]
loans: Map<String, Int> [persistent]
}
on lend(book: String, member: String) {
loans.set(book, member)
}
}What soma check prints:
$ soma check wrong.cell
error: duplicate memory slot 'loans' in cell 'Library'
--> wrong.cell:4:9
|
4 | loans: Map<String, Int> [persistent]
| ^
= code: E0006
✗ 1 error(s), 0 warning(s).The fix field of soma check --json: Remove the duplicate memory slot 'loans' in cell 'Library'.
The fix
On line 4, loans: Map<String, Int> [persistent] becomes loan_counts: Map<String, Int> [persistent]; 1 line is added after line 7.
wrong.cell → right.cell
--- wrong.cell
+++ right.cell
@@ -2,8 +2,9 @@
memory {
loans: Map<String, String> [persistent]
- loans: Map<String, Int> [persistent]
+ loan_counts: Map<String, Int> [persistent]
}
on lend(book: String, member: String) {
loans.set(book, member)
+ loan_counts.set(member, (loan_counts.get(member) ?? 0) + 1)
}
}With the fix, soma check accepts the program:
$ soma check right.cell
✓ All checks passed.