soma.cell

E0025: habit

E0025 habit — an idiom from another language that means something else in Soma.

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

The rule

Some method names come from other languages and do not exist in Soma; active.includes(code) is JavaScript. soma check refuses an unknown method and, for common ones, names the Soma form — here contains(xs, x). Any builtin can be called as a function or as a method, and soma describe --builtins lists them.

A program that triggers it

wrong.cell

cell Coupons {
    on is_valid(code: String) {
        let active = ["SPRING10", "WELCOME5", "VIP20"]
        return active.includes(code)
    }
}

What soma check prints:

$ soma check wrong.cell
error: no method 'includes' — in Soma: contains(xs, x). Any builtin is a method (xs.sort(), s.trim()); `soma describe --builtins` lists them
  --> wrong.cell:4:16
  |
4 |         return active.includes(code)
  |                ^
  = code: E0025
✗ 1 error(s), 0 warning(s).

The fix field of soma check --json: no method 'includes' — in Soma: contains(xs, x). Any builtin is a method (xs.sort(), s.trim()); `soma describe --builtins` lists them

On line 4, return active.includes(code) becomes return contains(active, code).

wrong.cell → right.cell

--- wrong.cell
+++ right.cell
@@ -2,5 +2,5 @@
     on is_valid(code: String) {
         let active = ["SPRING10", "WELCOME5", "VIP20"]
-        return active.includes(code)
+        return contains(active, code)
     }
 }

With the fix, soma check accepts the program:

$ soma check right.cell
✓ All checks passed.