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

Casting negative literals to unsigned doesn't work #2045

Closed
shuklaayush opened this issue Jul 26, 2023 · 2 comments · Fixed by #2153
Closed

Casting negative literals to unsigned doesn't work #2045

shuklaayush opened this issue Jul 26, 2023 · 2 comments · Fixed by #2153
Assignees
Labels
bug Something isn't working

Comments

@shuklaayush
Copy link
Contributor

shuklaayush commented Jul 26, 2023

Aim

I use -1 as u{X} syntax to get the unsigned max values. This doesn't seem to work in the new ssa.

use dep::std::println;

#[test]
fn test_cast() {
    let a: u8 = -1 as u8;
    // "0x30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000000"
    println(a);
    // assert(a == 0xff);
}

Expected Behavior

The above code should print out 0xff instead of MODULUS - 1

Bug

The test should pass

A workaround for now is to replace -1 as u8 with 0-1 as u8

To Reproduce

  1. Copy the code above
  2. Run nargo test

Installation Method

Compiled from source

Nargo Version

nargo 0.9.0 (git version hash: 66cb1fd, is dirty: false)

Additional Context

No response

Would you like to submit a PR for this Issue?

Maybe

Support Needs

No response

@shuklaayush shuklaayush added the bug Something isn't working label Jul 26, 2023
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir Jul 26, 2023
@kevaundray kevaundray added P-HIGH and removed E-LOW labels Jul 26, 2023
@kevaundray
Copy link
Contributor

@Ethan-000 have assigned this to you, if you have questions please ask them in here.

bumping @jfecher for visibility

@jfecher
Copy link
Contributor

jfecher commented Jul 26, 2023

I would think this should be handled by
https://github.com/noir-lang/noir/blob/master/crates/noirc_evaluator/src/ssa_refactor/ir/instruction.rs#L369-L377 but it seems like it is not

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
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants