soma.cell

W0013: unreachable

W0013 unreachable — code or states that cannot be reached.

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

The rule

soma check warns with W0013 when statements can never run, such as statements after a return (or a break) in the same block. In this example the audit entry is never written, although the handler looks as if it records every order. Move the statements before the return, or delete them if they are not needed.

A program that triggers it

wrong.cell

cell Orders {
    memory {
        orders: Map<String, Int> [persistent]
        audit: List<String> [persistent]
    }
    on place(id: String, total: Int) {
        orders.set(id, total)
        return id
        audit.push("placed {id} for {total}")
    }
}

What soma check prints:

$ soma check wrong.cell
warning: in Orders.place: unreachable code after `return`
  --> wrong.cell:9:9
  |
9 |         audit.push("placed {id} for {total}")
  |         ^
✓ 1 warning(s), no errors.

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

1 line is added after line 7; line 9 is removed.

wrong.cell → right.cell

--- wrong.cell
+++ right.cell
@@ -6,6 +6,6 @@
     on place(id: String, total: Int) {
         orders.set(id, total)
+        audit.push("placed {id} for {total}")
         return id
-        audit.push("placed {id} for {total}")
     }
 }

With the fix, soma check accepts the program:

$ soma check right.cell
✓ All checks passed.