E0103: break_outside_loop
E0103 break_outside_loop — break / continue outside a loop.
A compile-time error of soma check, the checker of the Soma programming language (soma explain E0103).
The rule
break and continue only mean something inside a for or while loop, and soma check reports E0103 anywhere else, here in match arms written like the cases of a C switch. A Soma match runs exactly one arm and never falls through to the next, so the arm needs no break. Delete it; to leave a handler early, use return.
A program that triggers it
wrong.cell
cell Billing {
face {
signal late_fee(status: String, days_late: Int) -> Int
}
on late_fee(status: String, days_late: Int) {
let fee = 0
match status {
"paid" -> {
fee = 0
break
}
"overdue" -> {
fee = 500 + days_late * 25
break
}
_ -> { fee = 0 }
}
return fee
}
}What soma check prints:
$ soma check wrong.cell
error: `break` outside a loop — it only means something inside `for` / `while` (to leave a handler, `return`)
--> wrong.cell:10:17
|
10 | break
| ^
= code: E0103
error: `break` outside a loop — it only means something inside `for` / `while` (to leave a handler, `return`)
--> wrong.cell:14:17
|
14 | break
| ^
= code: E0103
✗ 2 error(s), 0 warning(s).The fix field of soma check --json: it only means something inside `for` / `while` (to leave a handler, `return`)
The fix
Line 10 is removed; line 14 is removed.
wrong.cell → right.cell
--- wrong.cell
+++ right.cell
@@ -8,9 +8,7 @@
"paid" -> {
fee = 0
- break
}
"overdue" -> {
fee = 500 + days_late * 25
- break
}
_ -> { fee = 0 }With the fix, soma check accepts the program:
$ soma check right.cell
✓ All checks passed.