tact-lang / tact

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

Support mutually recursive functions #364

Open anton-trunov opened 1 month ago

anton-trunov commented 1 month ago

FunC supports those, but Tact's topological sorting of between module entries would prohibit mutual recursion.

The classical test case would be a mutually recursive implementation of the even and odd functions:

fun even(n: Int): Bool {
    if (n == 0) {
        return true;
    } else {
        return odd(n - 1);
    }
}

fun odd(n: Int): Bool {
    if (n == 0) {
        return false;
    } else {
        return even(n - 1);
    }
}

contract Test {

    get fun even(n: Int): Bool {
        return even(n);
    }

    get fun odd(n: Int): Bool {
        return odd(n);
    }
}