Diagnostic and cause
LinkImmutable binding mutation
- Family
- topaz
- Phase
- check
- Code
TPZ5003
Cause and conditions
An assignment through an immutable root binding is rejected with TPZ5003 at that root. Declare the root with let mut when subsequent assignment is required.
Related rule: Assignment requires a mutable root bindingResponse
Declare a local root with let mut when it must change. Otherwise, compute a new value and bind it separately.
Source evidence
- compiler/crates/topaz_diag/src/explain.rs at
151141d7bb44· 606-618 - compiler/crates/topaz_product_runtime/src/diagnostic.rs at
151141d7bb44· 64-64 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
151141d7bb44· 2212-2212 - compiler/crates/topaz_self_frontend/topaz/checker/statements.tpz at
151141d7bb44· 689-703 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
151141d7bb44· 2188-2229 - compiler/crates/topaz_self_frontend/topaz/checker/syntax_index.tpz at
151141d7bb44· 485-505
Compiler phase: check/runtime.
Compiler explanation: The program tried to assign through a binding that was not declared mutable.
Message templates are Pending. The explanation above is not an observed CLI message.
Observed for the candidate in Topaz 5.21.3. Execution
- error[TPZ5003]:
valueis immutable; declare it withlet mut
An assignment through an immutable root binding is rejected with TPZ5003 at that root. Declare the root with let mut when subsequent assignment is required.
Assignment requires a mutable root binding
An assignment through an immutable root binding is rejected with TPZ5003 at that root. Declare the root with let mut when subsequent assignment is required.
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/statements.tpz at
151141d7bb44· 689-703 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
151141d7bb44· 2188-2229 - compiler/crates/topaz_self_frontend/topaz/checker/syntax_index.tpz at
151141d7bb44· 485-505
Response
LinkDeclare a local root with let mut when it must change. Otherwise, compute a new value and bind it separately.
Reproduction and verification
LinkRejected program
Linklet value = 1value = 2
No stdout.
Expected result
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/statements.tpz at
151141d7bb44· 689-703 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
151141d7bb44· 2188-2229 - compiler/crates/topaz_self_frontend/topaz/checker/syntax_index.tpz at
151141d7bb44· 485-505
Repaired program
Linklet mut value = 1value = 2
Expected result
Expected result
Checking accepts the program. Exit code 0.
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/statements.tpz at
151141d7bb44· 689-703 - compiler/crates/topaz_self_frontend/topaz/checker/expression_core.tpz at
151141d7bb44· 2188-2229 - compiler/crates/topaz_self_frontend/topaz/checker/syntax_index.tpz at
151141d7bb44· 485-505