The description of a mutates function specifies that it can change the argument given in the self parameter.
For example, given the declaration,
let A: Int = 0;
and the mutates function,
extends mutates fun inc(self: Int) {
self += 1;
}
the statement,
A.inc();
will increase variable A.
However, if A was declared as a constant,
const A: Int = 0;
the statement,
A.inc();
will NOT increase A, and Tact will silently allow such attempt of changing A, contrary to expectation.
The reason for Tact silently allowing this, is that Tact carries out constant substitution. This means that A.inc() is actually 0.inc() during compilation. Hence, no actual attempt of changing A exists (and executing 0.inc() has the same effect as incrementing a variable local to inc initialized with 0). This silent behavior between constants and mutates functions should be documented in the description of mutates functions (for example, adding a note in https://docs.tact-lang.org/book/functions#mutable-functions).
The description of a
mutates
function specifies that it can change the argument given in theself
parameter.For example, given the declaration,
and the
mutates
function,the statement,
will increase variable
A
.However, if
A
was declared as a constant,the statement,
will NOT increase
A
, and Tact will silently allow such attempt of changingA
, contrary to expectation.The reason for Tact silently allowing this, is that Tact carries out constant substitution. This means that
A.inc()
is actually0.inc()
during compilation. Hence, no actual attempt of changingA
exists (and executing0.inc()
has the same effect as incrementing a variable local toinc
initialized with0
). This silent behavior between constants andmutates
functions should be documented in the description ofmutates
functions (for example, adding a note in https://docs.tact-lang.org/book/functions#mutable-functions).