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

Implement fromCell and fromSlice methods for structs #418

Merged
merged 8 commits into from
Jun 19, 2024

Conversation

Gusarich
Copy link
Member

Closes #344

  • I have updated CHANGELOG.md
  • I have added tests to demonstrate the contribution is correctly implemented: this usually includes both positive and negative tests, showing the happy path(s) and featuring intentionally broken cases
  • I have run all the tests locally and no test failure was reported
  • I have run the linter, formatter and spellchecker
  • I did not do unrelated and/or undiscussed refactorings

@anton-trunov anton-trunov added this to the v1.4.0 milestone Jun 14, 2024
@anton-trunov anton-trunov self-assigned this Jun 14, 2024
@Gusarich
Copy link
Member Author

Just realised that I didn't add any negative tests for struct parsing

Copy link
Member

@anton-trunov anton-trunov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need some tests to make sure the following works as expected.
First, the user defines a fromCell:

extends mutates fun fromCell(self: Cell, _: Cell): MyStruct1 {
  return MyStruct1 { ... };
}

And now the user is trying to do something weird:

contract StructsTester {
    receive() { }

    get fun fromCell1(src: Cell): MyStruct1 {
        let MyStruct1: Cell = beginCell().endCell();  // it's a cell here!
        let s: MyStruct1 = MyStruct1.fromCell(src);
        return s;
    }
}

What do you expect to happen in this case?

@Gusarich
Copy link
Member Author

@anton-trunov do you mean a user-defined function with the same name - fromCell or fromSlice?

I think it should work the same way as it works for all other built-ins such as toCell for structs, and set, get and del for maps.

@anton-trunov
Copy link
Member

@Gusarich Yep. Because right now this shadowing is allowed and it overrides the generated code.

@Gusarich
Copy link
Member Author

Gusarich commented Jun 16, 2024

@Gusarich Yep. Because right now this shadowing is allowed and it overrides the generated code.

Should we forbid such shadowing for all built-in functions?

UPD: oh, we actually wanted to do this already, but only implemented throwing errors for global.ts: #351

@anton-trunov
Copy link
Member

Yeah, we do not allow any form of shadowing in Tact. And if we do, it's a bug

@anton-trunov
Copy link
Member

btw, there is some merge conflicts

@Gusarich
Copy link
Member Author

Yeah, we do not allow any form of shadowing in Tact. And if we do, it's a bug

In this case maybe we should create a separate issue about that and resolve that in another PR?

@anton-trunov
Copy link
Member

In this case maybe we should create a separate issue about that and resolve that in another PR?

Yeah, there are issues like that, for instance #307. There is a special tag for those scope: var-scope Scoping rules for identifiers

Copy link
Member

@anton-trunov anton-trunov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Just some minor tweaks in the suggested changes

src/test/e2e-emulated/contracts/structs.tact Outdated Show resolved Hide resolved
src/test/e2e-emulated/contracts/structs.tact Outdated Show resolved Hide resolved
src/types/resolveExpression.ts Outdated Show resolved Hide resolved
src/abi/struct.ts Outdated Show resolved Hide resolved
src/abi/struct.ts Outdated Show resolved Hide resolved
src/abi/struct.ts Outdated Show resolved Hide resolved
src/abi/struct.ts Outdated Show resolved Hide resolved
src/abi/struct.ts Outdated Show resolved Hide resolved
src/abi/struct.ts Outdated Show resolved Hide resolved
@anton-trunov anton-trunov merged commit 880d82b into tact-lang:main Jun 19, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consider adding more higher-level approaches to build and parse Cells, which would be compile-time friendly
2 participants