type.assign_immutable
A variable declared without mut, or a parameter, is given a new value.
Area 3, Logic; not declinable; the next step is usually the agent's.
Why Jadpo refuses it
A var never changes, so a reader who sees its line knows its value
everywhere below it. Only a var mut can be pointed at a new value, and
the mut warns the reader to look for where it changes. Parameters never
change either. Letting a plain var change would break what its line
promises.
What it looks like
main.jadpo:
type Choice = Text {}function replace(initial: Choice, replacement: Choice) -> Choice { var fixed: Choice = initial fixed = replacement return fixed}
error fixed can't be changed
--> main.jadpo:5:5
|4 | var fixed: Choice = initial | ----- declared without `mut`5 | fixed = replacement | ^^^^^ assigned here
- reason
varnames a value that never changes; only avar mutcan be pointed at a new value.- next
- Declare it
var mut fixed(agent) - rule
- type.
assign_ immutable - help
- https://jadpo.
dev/docs/errors/type. assign_ immutable
(agent) at the end of the next: line means your coding agent can make
the fix itself.
Assigning a parameter is the same error:
main.jadpo:
type Choice = Text {}function replace(initial: Choice, replacement: Choice) -> Choice { initial = replacement return initial}
error initial can't be changed
--> main.jadpo:4:5
|3 | function replace(initial: Choice, replacement: Choice) -> Choice { | ------- a parameter4 | initial = replacement | ^^^^^^^ assigned here
- reason
- Parameters never change; only a
var mutcan be pointed at a new value. - next
- Copy
initialinto avar mutwith a name of its own, and change that (agent) - rule
- type.
assign_ immutable - help
- https://jadpo.
dev/docs/errors/type. assign_ immutable
How to fix it
If the variable is meant to change, declare it var mut:
var mut fixed: Choice = initialfixed starts as initial and is then pointed at replacement. It can
only ever hold a Choice.
If a parameter is meant to change, copy it into a var mut with a
name of its own, and change that:
var mut chosen: Choice = initial chosen = replacement return chosen
initial keeps the value the caller passed, and chosen is the one that
changes.
Related
Markdown for agents: /docs/errors/type.assign_immutable.md.Built from Jadpo main at aee2e8f.