E0109: type_mismatch
E0109 type_mismatch — an expression whose inferred type cannot be used where it stands.
A compile-time error of soma check, the checker of the Soma programming language (soma explain E0109).
The rule
soma check infers the types of expressions and reports E0109 when one cannot be used where it stands, such as + between a String and an Int, a comparison of a String with an Int, or an ordering against (). Soma does not convert silently: adding a String and an Int fails at run time with "cannot add String and Int", so check refuses it when it can see both types. Build text with interpolation ("{customer}: {total_cents} cents") or to_string(n), and parse text with to_int / to_float when you mean a sum.
A program that triggers it
wrong.cell
cell Invoice {
face {
signal summary(customer: String, total_cents: Int) -> String
}
on summary(customer: String, total_cents: Int) {
return "Invoice for " + customer + ": " + total_cents + " cents"
}
}What soma check prints:
$ soma check wrong.cell
error: cannot add a String and an Int: `"Invoice for " + customer + ": " + total_cents` — build the text with interpolation (`"{a}{b}"`) or to_string(n); for a sum, parse the text first (to_int, to_float)
--> wrong.cell:6:16
|
6 | return "Invoice for " + customer + ": " + total_cents + " cents"
| ^
= code: E0109
✗ 1 error(s), 0 warning(s).The fix field of soma check --json: build the text with interpolation (`"{a}{b}"`) or to_string(n); for a sum, parse the text first (to_int, to_float)
The fix
On line 6, return "Invoice for " + customer + ": " + total_cents + " cents" becomes return "Invoice for {customer}: {total_cents} cents".
wrong.cell → right.cell
--- wrong.cell
+++ right.cell
@@ -4,5 +4,5 @@
}
on summary(customer: String, total_cents: Int) {
- return "Invoice for " + customer + ": " + total_cents + " cents"
+ return "Invoice for {customer}: {total_cents} cents"
}
}With the fix, soma check accepts the program:
$ soma check right.cell
✓ All checks passed.