ErrorsValues and types · rule
type.missing_field
An object value is built without one of the fields its type declares.
Area 2, Values and types; not declinable; the next step is usually the agent's.
Why Jadpo refuses it
An object value is written with its type name and every field, so a
value always has what its type promises and nothing reads a field that
was never set. A field that may hold nothing is declared T? and still
given, as none, so leaving it empty is a choice you can see.
What it looks like
main.jadpo:
type Receipt = Output { email: Email}function incomplete_receipt() -> Receipt { return Receipt {}}
error Receipt is missing email
--> main.jadpo:6:12
|6 | return Receipt {} | ^^^^^^^ fields missing
- reason
- Every field of
Receiptis given when a value is built; a field that may be absent is declaredT?and given asnone. - next
- Add
email: ...to the block (agent) - rule
- type.
missing_ field - help
- https://jadpo.
dev/docs/errors/type. missing_ field
(agent) at the end of the next: line means your coding agent can make
the fix itself.
How to fix it
If the value has the field, give it in the block:
function incomplete_receipt(email: Email) -> Receipt { return Receipt { email: email }}
Every Receipt now carries the email it is sent to.
If a receipt may have no email, declare the field Email? and give
it as none:
type Receipt = Output { email: Email?}function incomplete_receipt() -> Receipt { return Receipt { email: none }}
Code that reads email now handles both cases, usually with match.
Related
Markdown for agents: /docs/errors/type.missing_field.md.Built from Jadpo main at aee2e8f.