You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Are you using the latest released (or pre-released, a.k.a. "next") version?
I'm using the latest Tact version
Tact source code
contract Test {
a: Int;
init() {
let contract_copy = self;
self.a = 5;
self = contract_copy; // Does this line "uninitialize" self.a?
}
}
Relevant Tact/build system log output
This is the generated func code of the init method:
(int) $Test$_contract_init() impure inline_ref {
var (($self'a)) = (null());
var ($contract_copy'a) = ($self'a);$self'a = 5; ($self'a) = ($contract_copy'a); return ($self'a);
}
What happened?
Field $self'a will be initialized to null() after $Test$_contract_init executes. Is null() a valid value for an Int?
What did you expect?
Probably an error message explaining that self should not be assigned in the init method.
Steps to reproduce
No response
How do you run Tact?
Tact CLI
Anything else?
No response
The text was updated successfully, but these errors were encountered:
Actually, reading the entire contract state using self should not be allowed in the init function because someone could write something like this:
contract Test {
a: Int;
init() {
let contract_copy = self;
self.a = 5;
self.a = contract_copy.a;
}
}
which has the same effect. Note we are not assigning the variable self this time: we are just reading it.
Reading variable self in init does not make sense, because init is supposed to initialize the contract. Therefore, self by itself does not have any meaning until init finishes execution!
However, it is OK to read specific fields inside init, like self.a, as long as those fields have been initialized. For example, the compiler correctly rejects this:
contract Test {
a: Int;
init() {
let a_copy = self.a;
self.a = 5;
self.a = a_copy;
}
}
Are you using the latest released (or pre-released, a.k.a. "next") version?
Tact source code
Relevant Tact/build system log output
What happened?
Field
$self'a
will be initialized tonull()
after$Test$_contract_init
executes. Isnull()
a valid value for anInt
?What did you expect?
Probably an error message explaining that
self
should not be assigned in theinit
method.Steps to reproduce
No response
How do you run Tact?
Tact CLI
Anything else?
No response
The text was updated successfully, but these errors were encountered: