E0040: face_return_type
E0040 face_return_type — a handler returns a value its face signal does not declare.
A compile-time error of soma check, the checker of the Soma programming language (soma explain E0040).
The rule
A handler returns a literal whose type differs from the return type its face signal declares, for example a String where the face says -> Int. The face is the cell's contract with its callers, so Soma refuses a body that contradicts it. Return a value of the declared type, or change the declared type in the face if the contract was wrong.
A program that triggers it
wrong.cell
cell Wallet {
face {
signal balance(owner: String) -> Int
}
memory {
balances: Map<String, Int> [persistent]
}
on balance(owner: String) {
let cents = balances.get(owner) ?? 0
return "{owner} has {cents} cents"
}
}What soma check prints:
$ soma check wrong.cell
error: handler 'balance' returns a String literal but its face declares `-> Int` — fix the value or the face
--> wrong.cell:10:16
|
10 | return "{owner} has {cents} cents"
| ^
= code: E0040
✗ 1 error(s), 0 warning(s).The fix field of soma check --json: fix the value or the face
The fix
On line 10, return "{owner} has {cents} cents" becomes return cents.
wrong.cell → right.cell
--- wrong.cell
+++ right.cell
@@ -8,5 +8,5 @@
on balance(owner: String) {
let cents = balances.get(owner) ?? 0
- return "{owner} has {cents} cents"
+ return cents
}
}With the fix, soma check accepts the program:
$ soma check right.cell
✓ All checks passed.