Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix contract storage analysis for init() #2074

Closed
anton-trunov opened this issue Feb 28, 2025 · 1 comment · Fixed by #2077
Closed

Fix contract storage analysis for init() #2074

anton-trunov opened this issue Feb 28, 2025 · 1 comment · Fixed by #2077
Assignees
Labels
feature: receivers Process internal, external, bounced incoming messages kind: bug Something isn't working or isn't right
Milestone

Comments

@anton-trunov
Copy link
Member

contract Tester {
    x: Int;

    init() { self.x = 42 }

    receive() { } // does not modify the contract state, but we need to save it when `init()` is called

    get fun x(): Int { return self.x }
}
@anton-trunov anton-trunov added feature: receivers Process internal, external, bounced incoming messages kind: bug Something isn't working or isn't right labels Feb 28, 2025
@anton-trunov anton-trunov added this to the v1.6.0 milestone Feb 28, 2025
@anton-trunov anton-trunov self-assigned this Feb 28, 2025
@anton-trunov
Copy link
Member Author

The code above is essentially the following one with everything explicit:

contract Foo(
    lazyDeploymentDone: Bool;
    x: Int;
) {
    fun init() {
        if (!lazyDeploymentDone) {
            self.x = 42;
            self.lazyDeploymentDone = true
        }
    }

    receive() {
        self.init();
    }
}

So, any contract with init() won't benefit from the contract storage optimization, since any receiver needs to store the contract state.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature: receivers Process internal, external, bounced incoming messages kind: bug Something isn't working or isn't right
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant