ErrorsValues and types · rule
type.invalid_literal
A literal value breaks a rule of the type it goes into, such as a number below the type's min.
Area 2, Values and types; not declinable; the next step is usually the agent's.
Why Jadpo refuses it
A literal takes the type it goes into, whether it is returned, assigned,
passed or written as Quantity(0). Its value is known while compiling,
so Jadpo checks it against every rule of that type then, rather than
leave a value that can never be valid to fail when the code runs.
What it looks like
main.jadpo:
type Quantity = Int { min: 1 max: 1000}function starting_quantity() -> Quantity { return 0}
error 0 isn't a valid Quantity
--> main.jadpo:7:12
|7 | return 0 | ^ breaks `min: 1`
- reason
Quantitydeclaresmin: 1, and the value is below 1. A literal is checked against every rule while compiling.- next
- Use a value that
Quantityallows (agent) - rule
- type.
invalid_ literal - help
- https://jadpo.
dev/docs/errors/type. invalid_ literal
(agent) at the end of the next: line means your coding agent can make
the fix itself.
How to fix it
If the value is wrong, use one the type allows:
return 1starting_quantity now returns 1, the smallest Quantity.
If the value is right and the rule is wrong, change the type's rule:
min: 0Every Quantity may now be 0, not only this one, so check the other
places that rely on a quantity of at least 1.
Related
Markdown for agents: /docs/errors/type.invalid_literal.md.Built from Jadpo main at aee2e8f.