tact-lang / tact

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

Storage vars cannot be initialized by struct instances, `emptyMap`, and slices #400

Open byakuren-hijiri opened 1 week ago

byakuren-hijiri commented 1 week ago

The following snippet cannot be compiled:

// only this test case was found by the fuzzer
struct A {
    a: Bool;
}
contract Test {
    s: A = A {a: false};
}
"<unknown>:13:14: Expected constant value, got A

And also, emptyMap() does not work:

// found after manual code inspection
contract Test {
    m: map<Int, Int> = emptyMap();
}

Slices don't work as well.

// found after manual code inspection
contract Test {
    sl: Slice = beginCell().endCell().asSlice();
}

Note that if all the above initializing expressions move to init() and use assignment, everything works.

Related: https://github.com/tact-lang/tact/issues/284