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

Incorrect upcasting of signed integers for comparsion #5227

Closed
nventuro opened this issue Jun 11, 2024 · 3 comments
Closed

Incorrect upcasting of signed integers for comparsion #5227

nventuro opened this issue Jun 11, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@nventuro
Copy link
Contributor

nventuro commented Jun 11, 2024

Aim

After quite a bit of head-scratching I noticed certain signed integers seem to be incorrectly upcast when performing comparisons.

Bug

I expected the following test to pass, but it doesn't:

#[test]
fn test() {
    let a = 5;
    let b = -1;

    assert(a > b);
}

The test does pass as expected if I do a as i32.

@nventuro nventuro added the bug Something isn't working label Jun 11, 2024
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir Jun 11, 2024
@jfecher
Copy link
Contributor

jfecher commented Jun 11, 2024

Looks like a and b are defaulting to u64s since > was used (otherwise they'd default to Fields). The -1 then presumably overflowed the u64's range.

@TomAFrench
Copy link
Member

TomAFrench commented Jun 13, 2024

#4631 is relevant here as this would have been caught and fixed by Nico if we errored on this case rather than wrapping around.

@asterite
Copy link
Collaborator

asterite commented Jul 5, 2024

Fixed by #5375

Now the above program gives this error:

[one] Running 1 test function
[one] Testing test... error: The value `-1` cannot fit into `u32` which has range `0..=4294967295`
  ┌─ src/main.nr:4:13
  │
4 │     let b = -1;
  │             --

@asterite asterite closed this as completed Jul 5, 2024
@github-project-automation github-project-automation bot moved this from 📋 Backlog to ✅ Done in Noir Jul 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
Development

No branches or pull requests

4 participants