soma.cell

W0015: interpolation_recoverable

W0015 interpolation_recoverable — an undefined interpolation variable inside try / assert_fails.

A warning of soma check, the checker of the Soma programming language (soma explain W0015).

The rule

An undefined name is normally a check error, but inside try { } (or in a handler that a test expects to fail with assert_fails) the failure would be caught at run time, so soma check reports it as warning W0015 instead; this applies to a plain variable as well as to one inside a {…} string interpolation. The danger is that the typo becomes a silently handled error: here quantiy makes every call take the error branch, and unit_price(1000, 4) returns 0. Fix the name (quantity); the message suggests the closest one in scope.

A program that triggers it

wrong.cell

cell Pricing {
    on unit_price(total_cents: Int, quantity: Int) {
        let r = try { idiv(total_cents, quantiy) }
        if r.error != () {
            return 0
        }
        return r.value
    }
}

What soma check prints:

$ soma check wrong.cell
warning: undefined variable 'quantiy' (did you mean 'quantity'?) — no let, parameter, loop variable, match binding or memory slot with that name is in scope (recoverable here — inside try { }, or in a handler a test expects to fail — so not an error)
  --> wrong.cell:3:41
  |
3 |         let r = try { idiv(total_cents, quantiy) }
  |                                         ^
✓ 1 warning(s), no errors.

The fix field of soma check --json: Review and address the reported warning.

On line 3, let r = try { idiv(total_cents, quantiy) } becomes let r = try { idiv(total_cents, quantity) }.

wrong.cell → right.cell

--- wrong.cell
+++ right.cell
@@ -1,5 +1,5 @@
 cell Pricing {
     on unit_price(total_cents: Int, quantity: Int) {
-        let r = try { idiv(total_cents, quantiy) }
+        let r = try { idiv(total_cents, quantity) }
         if r.error != () {
             return 0

With the fix, soma check accepts the program:

$ soma check right.cell
✓ All checks passed.