Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#[tailcall] macro panics #18

Open
fosskers opened this issue Feb 13, 2024 · 2 comments
Open

#[tailcall] macro panics #18

fosskers opened this issue Feb 13, 2024 · 2 comments

Comments

@fosskers
Copy link

fosskers commented Feb 13, 2024

Hi there, trying to test out the library, although it seems to be panicking. Here's the code I'm testing:

use std::path::Path;

#[tailcall::tailcall]
fn recurse(n: u64) -> u64 {
    let file = Path::new("src/main.rs");
    let len = file.metadata().unwrap().len();

    if n >= 1_000_000_000 {
        n
    } else {
        recurse(len + n)
    }
}

fn main() {
    let res = recurse(1);

    println!("Done: {res}");
}

The compiler tells me:

error: custom attribute panicked
 --> src/main.rs:3:1
  |
3 | #[tailcall::tailcall]
  | ^^^^^^^^^^^^^^^^^^^^^
  |
  = help: message: expected tuple expression

Strangely, the message expected tuple expression can't be found in this repo, so is that coming from Rust itself? Thank you kindly.

@fosskers
Copy link
Author

Hi there, any thoughts on this?

@alecdotninja
Copy link
Owner

There seems to be a bug affecting functions with only a single argument. 🙃

Until I get more time to look into this issue, you can work around the problem by adding a second dummy argument:

use std::path::Path;

#[tailcall::tailcall]
fn recurse(n: u64, _d: ()) -> u64 {
    let file = Path::new("src/main.rs");
    let len = file.metadata().unwrap().len();

    if n >= 1_000_000_000 {
        n
    } else {
        recurse(len + n, ())
    }
}


fn main() {
    let res = recurse(1, ());

    println!("Done: {res}");
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants