tact-lang / tact

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

FunC cannot compile `try-catch` that always return #450

Open anton-trunov opened 1 week ago

anton-trunov commented 1 week ago

Compilation of the following contract

contract TryCatchTester {
    get fun testTryCatch(): Int {
        try {
            throw(101);
        } catch (e) {
            return e;
        }
    }
}

fails with

Func compilation error: /Users/anton_1/ton/tact/contract-throw/throw_TryCatchTester.code.fc:25:1: error: previous function return type (tuple, int) cannot be unified with implicit end-of-block return type (): cannot unify type () with (tuple, int) }

To me it looks like a FunC issue. As a workaround, one can add something like nativeThrowUnless(1111111, false) after the try-catch statement: Tact's return reachability analysis won't complain and FunC is happy to compile the program with unreachable code.