soma.cell

E0074: param_shadows_slot

E0074 param_shadows_slot — a parameter named like a memory slot.

A compile-time error of soma check, the checker of the Soma programming language (soma explain E0074).

The rule

A handler parameter may not have the name of a memory slot of its cell, because reads and writes of that name inside the handler would mix the parameter and the slot. Rename the parameter (here borrower) and keep the slot name for the slot.

A program that triggers it

wrong.cell

cell Library {
    memory {
        loans: Map<String, String> [persistent]
    }
    on lend(book: String, loans: String) {
        loans.set(book, loans)
        return book
    }
}

What soma check prints:

$ soma check wrong.cell
error: parameter `loans` of `lend` has the name of the memory slot `loans` — reads and writes of `loans` in this handler would mix the two; rename the parameter (e.g. `new_loans`)
  --> wrong.cell:5:5
  |
5 |     on lend(book: String, loans: String) {
  |     ^
  = code: E0074
✗ 1 error(s), 0 warning(s).

The fix field of soma check --json: reads and writes of `loans` in this handler would mix the two; rename the parameter (e.g. `new_loans`)

Lines 5–6 are rewritten.

wrong.cell → right.cell

--- wrong.cell
+++ right.cell
@@ -3,6 +3,6 @@
         loans: Map<String, String> [persistent]
     }
-    on lend(book: String, loans: String) {
-        loans.set(book, loans)
+    on lend(book: String, borrower: String) {
+        loans.set(book, borrower)
         return book
     }

With the fix, soma check accepts the program:

$ soma check right.cell
✓ All checks passed.