E0017: sum_type_issue
E0017 sum_type_issue — a match over a sum type is not exhaustive, or names an unknown variant.
A compile-time error of soma check, the checker of the Soma programming language (soma explain E0017).
The rule
A match over a value of a cell type with variants must have an arm for every variant (or a _ arm), and may not name a variant the type does not have. soma check names the missing variant, so adding Refunded to the type cannot leave a match that silently falls through. Add the missing arm.
A program that triggers it
wrong.cell
cell type Payment {
variants {
Charged { tx: String }
Declined { reason: String }
Refunded { tx: String }
}
}
cell Receipts {
on describe(p: Payment) {
return match p {
Charged { tx } -> "paid ({tx})"
Declined { reason } -> "declined: {reason}"
}
}
}What soma check prints:
$ soma check wrong.cell
error: non-exhaustive match on 'Payment': missing variant `Refunded`
--> wrong.cell:11:16
|
11 | return match p {
| ^
= code: E0017
✗ 1 error(s), 0 warning(s).The fix field of soma check --json: non-exhaustive match on 'Payment': missing variant `Refunded`
The fix
1 line is added after line 13.
wrong.cell → right.cell
--- wrong.cell
+++ right.cell
@@ -12,4 +12,5 @@
Charged { tx } -> "paid ({tx})"
Declined { reason } -> "declined: {reason}"
+ Refunded { tx } -> "refunded ({tx})"
}
}With the fix, soma check accepts the program:
$ soma check right.cell
✓ All checks passed.