leo icon indicating copy to clipboard operation
leo copied to clipboard

[Bug] Panic when recursion

Open yujqiao opened this issue 3 years ago • 1 comments

🐛 Bug Report

leo panicked when the function is recursive.

A newcomer may not be aware that the unbounded recursion is NOT supported. A panic doesn't help users.

Steps to Reproduce

leo run

Code snippet to reproduce

// The 'hello-world' main function.
function main(a: u32, b: u32) -> u32 {
    return a + b;
}

function count(a: u32) {
    if a > 0 {
        count(a-1);
    }
}

Stack trace & error message

thread 'main' panicked at 'already borrowed: BorrowMutError', asg/src/expression/variable_ref.rs:172:41
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Expected Behavior

The compiler emits an error, addressing that unbounded recursion is not supported.

Your Environment

  • 8bce3a396a8691ad1f7045b56814f6bb4d9e5a31
  • 1.58.0
  • archlinux

yujqiao avatar Jan 24 '22 10:01 yujqiao

On master it is not supported, but it's supported on the staging branch and soon it will be supported on the testnet2 branch.

gluax avatar Jan 24 '22 17:01 gluax

As of Leo v1.6.2, the error message has been updated:

Error [ETYC0372048]: Cannot call a local transition function from a transition function.

collinc97 avatar Jan 05 '23 19:01 collinc97