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

Compiler allows changing fields in getter functions #818

Open
1 task done
jeshecdom opened this issue Sep 13, 2024 · 5 comments
Open
1 task done

Compiler allows changing fields in getter functions #818

jeshecdom opened this issue Sep 13, 2024 · 5 comments
Assignees
Labels
bug Something isn't working typechecker
Milestone

Comments

@jeshecdom
Copy link
Contributor

Are you using the latest released (or pre-released, a.k.a. "next") version?

  • I'm using the latest Tact version

Tact source code

extends mutates fun changeMe(self: Int) {
    self = 10;
}

contract Test {
    a: Int = 5;

    get fun changeFieldDirectly(): Int {
        self.a = 10;
        return self.a;
    }

    get fun changeFieldByCopyingContract(): Int {
        let contract_copy = self;
        contract_copy.a = 10;
        self = contract_copy;
        return self.a;
    }

    get fun changeFieldByMutatingFun(): Int {
        self.a.changeMe();
        return self.a;
    }
}

Relevant Tact/build system log output

No response

What happened?

In the above code, no error is reported, even though field self.a is being changed in three different ways in getter functions.

What did you expect?

An error stating that self.a or self cannot be assigned in getter functions. The semantics of getter functions state that they cannot change the contract state.

Steps to reproduce

No response

How do you run Tact?

Tact CLI

Anything else?

No response

@jeshecdom jeshecdom added the bug Something isn't working label Sep 13, 2024
@anton-trunov
Copy link
Member

This is kind of handled for now in the Tact docs by saying this is "undefined behavior". Will be solved in the new typechecker

@anton-trunov anton-trunov self-assigned this Sep 15, 2024
@anton-trunov anton-trunov added this to the v1.6.0 milestone Sep 15, 2024
@Gusarich
Copy link
Member

Do we really need to forbid that? Isn't it enough to just clarify that all made changes won't be applied (I'm sure it's already stated somewhere)

@anton-trunov
Copy link
Member

Yeah, if it definitely dead code we should not allow that

@Gusarich
Copy link
Member

Yeah, if it definitely dead code we should not allow that

what if someone wants to call a few state-modifying functions inside of a getter in order to calculate something to return?

@anton-trunov
Copy link
Member

what if someone wants to call a few state-modifying functions inside of a getter in order to calculate something to return?

this is a very good point, let's see if we can address it or just delegate some dead code analysis to the misti static analyzer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working typechecker
Projects
None yet
Development

No branches or pull requests

3 participants