tact-lang / tact

Tact compiler main repository
https://tact-lang.org
MIT License
382 stars 108 forks source link

the compiler allows you to create getters with arguments (tuple in my issue) that cannot be used on the stack #778

Open tamerland05 opened 1 month ago

tamerland05 commented 1 month ago

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

Tact source code

No response

Relevant Tact/build system log output

No response

What happened?

the compiler allows you to create getters that take the message type as arguments (https://github.com/Architec-Ton/Architecton-p2p/blob/bf547222/contracts/order/router.tact ) compiled in func as a tuple type, which in turn is not supported in the stack structure: "Unsupported stack item type: tuple" (https://github.com/ton-org/ton/blob/09cef89fe7eca49c7e9d1dd4347dcde1a29d09e2/src/client/api/HttpApi.ts#L132)

What did you expect?

it seems that when trying to build a contract with a getter accepting a message, a compilation error should occur, however, it did not happen.

Steps to reproduce

https://github.com/Architec-Ton/Architecton-p2p/blob/bf547222 - try to npx blueprint build Router and call await Router.from...(...).getCalculateOrder(provider.provider(provider.sender().address!), { $$type: 'InitData', seller: provider.sender().address!, nonce: BigInt(Date.now()) }) you get: image

How do you run Tact?

Blueprint

Anything else?

No response

anton-trunov commented 1 month ago

@tamerland05 Thank you for raising the issue. I checked the compiler code and it looks fine. I also added two more tests for the cases when a message is passed as a parameter to a getter and to an init() and it also works fine. You can check the testing PR here: #792.

when trying to build a contract with a getter accepting a message, a compilation error should occur, however, it did not happen.

so this does not look as a valid assumption to me

Could you perhaps try reproducing it locally using Sandbox tests as I tried with #792?

tamerland05 commented 1 month ago

well, in the case that you have emulated, the methods from the tact code when compiled into func had the argumet type (cell, int), however, in my case https://github.com/tamerland05/CheckMessageInGetter/blob/main/build/Getters/tact_Test.code.fc#L140 the SetIdAndData type, the same as yours, is compiled into tuple, which is no longer supported by the tvm stack, I don't know why this happens, but perhaps this is due to the fact that I put SetIdAndData in the init of the contract. The tests work, but as far as I looked at the sanbox code, it does not fully emulate the behavior of tvm, at least in get methods. However, the error is clearly visible when I deploy the contract to the testnet and try to call this get method: image

It would be great if you would clone the repository and try to run the getters yourself, even on my contract EQA064UrLu0seP_n6TgA7nIoPIMy8K0_8rnYaAREJ4JMFpgy, even on your own pre-installed (just take other init values) and see this error yourself, however, the bug investigation should probably be stopped even when tuple appears in the func code

anton-trunov commented 1 month ago

tuple, which is no longer supported by the tvm stack

Tuples are supported by TVM, it's one of the native types of TVM

tamerland05 commented 1 month ago

hmm, then maybe this bug is related to the fact that @ton does not support tuple for sending, because the error clearly says so