leo/docs/error-guides/parser/mut_self_parameter.md
2022-02-28 09:42:37 -08:00

733 B

Deprecated mut parameter

Example

This error occurs when a function parameter is marked as mut.

Erroneous code example:

circuit Foo {
    bar: u8,

    function bar(mut self) {
        self.bar = 0;
    }
}

The compiler will reject this code with, for example...:

Error [EPAR0370019]: `mut self` is no longer accepted. Use `&self` if you would like to pass in a mutable reference to `self`
    --> test.leo:4:18
     |
   4 |     function bar(mut self) {
     |                  ^^^^^^^^

Solution

As the mut modifier is implicitly assumed, the solution is to remove the mut modifier from self:

circuit Foo {
    bar: u8,

    function bar(self) {
        self.bar = 0;
    }
}