E0110: unknown_field
E0110 unknown_field — a field the record type does not declare.
A compile-time error of soma check, the checker of the Soma programming language (soma explain E0110).
The rule
When soma check knows a value's record type (a cell type with one variant with named fields, here Line), reading a field the type does not declare is reported as E0110, with the list of the fields it does have. At run time an undeclared field reads as (), so l.quantity * l.unit_cents would fail at run time instead of naming the typo. Use the declared name (l.qty), or add the field to the type. The same code covers a field no variant of a sum type declares, and a field other than value, error, kind, detail read on a try result.
A program that triggers it
wrong.cell
cell type Line { variants { Line { sku: String, qty: Int, unit_cents: Int } } }
cell Order {
face {
signal total(lines: List<Line>) -> Int
}
on total(lines: List<Line>) {
let cents = 0
for l in lines {
cents += l.quantity * l.unit_cents
}
return cents
}
}What soma check prints:
$ soma check wrong.cell
error: `l.quantity`: record type 'Line' has no field 'quantity' — its fields are [sku, qty, unit_cents]; an undeclared field reads as `()`
--> wrong.cell:10:22
|
10 | cents += l.quantity * l.unit_cents
| ^
= code: E0110
✗ 1 error(s), 0 warning(s).The fix field of soma check --json: its fields are [sku, qty, unit_cents]; an undeclared field reads as `()`
The fix
On line 10, cents += l.quantity * l.unit_cents becomes cents += l.qty * l.unit_cents.
wrong.cell → right.cell
--- wrong.cell
+++ right.cell
@@ -8,5 +8,5 @@
let cents = 0
for l in lines {
- cents += l.quantity * l.unit_cents
+ cents += l.qty * l.unit_cents
}
return centsWith the fix, soma check accepts the program:
$ soma check right.cell
✓ All checks passed.