soma.cell

E0038: native_vocabulary

E0038 native_vocabulary — a [native] handler uses something native code does not have.

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

The rule

A [native] handler is compiled to Rust and may only use the native vocabulary: Int, Float, Bool and String values, arithmetic, if, while, for i in range(a, b), and the buffer, hashmap and strbuf primitives. Lists, maps, method calls, slots, try, match and interpolation are refused at check time, and the message names the first construct found. Rewrite the loop with scalar locals (an accumulator instead of a list), or drop [native] and let the interpreter run the handler.

A program that triggers it

wrong.cell

cell Risk {
    face {
        signal total_exposure(n: Int) -> Int
    }
    on total_exposure(n: Int) [native] {
        let positions = []
        for i in range(0, n) {
            positions.push(i * 100)
        }
        return sum(positions)
    }
}

What soma check prints:

$ soma check wrong.cell
error: handler 'total_exposure' is marked [native] but uses method call (not allowed in native handlers) — the native vocabulary is numbers, buffer/hashmap/strbuf primitives and sibling [native] handlers (see `soma docs native`); drop [native] or move the rest out
  --> wrong.cell:5:5
  |
5 |     on total_exposure(n: Int) [native] {
  |     ^
  = code: E0038
✗ 1 error(s), 0 warning(s).

The fix field of soma check --json: the native vocabulary is numbers, buffer/hashmap/strbuf primitives and sibling [native] handlers (see `soma docs native`); drop [native] or move the rest out

On line 6, let positions = [] becomes let total = 0; on line 8, positions.push(i * 100) becomes total = total + i * 100; on line 10, return sum(positions) becomes return total.

wrong.cell → right.cell

--- wrong.cell
+++ right.cell
@@ -4,9 +4,9 @@
     }
     on total_exposure(n: Int) [native] {
-        let positions = []
+        let total = 0
         for i in range(0, n) {
-            positions.push(i * 100)
+            total = total + i * 100
         }
-        return sum(positions)
+        return total
     }
 }

With the fix, soma check accepts the program:

$ soma check right.cell
✓ All checks passed.