soma.cell

E1005: reserved_word

E1005 reserved_word — a keyword used as a name.

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

The rule

Some keywords (agent, tool, cell, on, given, promise, use, in and others) can never be used as a variable, parameter or field name, because the parser reads them as the start of a construct. soma check names the word and suggests a rename such as agent_id. Rename the parameter (here agent becomes assignee); to read a JSON field with that name, index it with a string: d["agent"].

A program that triggers it

wrong.cell

cell Helpdesk {
    memory {
        owners: Map<String, String> [persistent]
    }
    on assign(ticket: String, agent: String) {
        owners.set(ticket, agent)
        return "{ticket} -> {agent}"
    }
}

What soma check prints:

$ soma check wrong.cell
error: `agent` is a reserved word in Soma and cannot name a variable, parameter or field — rename it (`agent_id`, `the_agent`); to read a JSON field of that name write `d["agent"]`
  --> wrong.cell:5:31
  |
5 |     on assign(ticket: String, agent: String) {
  |                               ^
  = code: E1005

Lines 5–7 are rewritten.

wrong.cell → right.cell

--- wrong.cell
+++ right.cell
@@ -3,7 +3,7 @@
         owners: Map<String, String> [persistent]
     }
-    on assign(ticket: String, agent: String) {
-        owners.set(ticket, agent)
-        return "{ticket} -> {agent}"
+    on assign(ticket: String, assignee: String) {
+        owners.set(ticket, assignee)
+        return "{ticket} -> {assignee}"
     }
 }

With the fix, soma check accepts the program:

$ soma check right.cell
✓ All checks passed.