You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Noir throws an error saying that "u32 cannot be used in a unary operation" when directly assigning a negative integer literal to an unsigned integer type.
let a:u32 = -1;
However, if you do some operations on the negative integer literal, the error is not thrown.
let a:u32 = -1 - 1;
Expected Behavior
Noir should not throw an error when directly assigning a negative integer literal to an unsigned integer type.
Bug
Create a new Noir project with the following command:
noir new neg
Save the following code into src/main.noir:
fnmain(){let a:u32 = -1;}
Run nargo prove and observe the following error:
warning: unused variable a
┌─ /home/Jurarpereurs/neg/src/main.nr:2:9
│
2 │ let a: u32 = -1;
│ - unused variable
│
error: u32 cannot be used in a unary operation
┌─ /home/Jurarpereurs/neg/src/main.nr:2:18
│
2 │ let a: u32 = -1;
│ --
│
Error: Aborting due to 1 previous error
Location:
crates/nargo_cli/src/cli/mod.rs:79:5
To see that the error is not thrown when doing some operations on the negative integer literal, save the following code into src/main.noir:
fnmain(){let a:u32 = -1 - 1;}
Run nargo prove and observe that the error is not thrown.
To Reproduce
Create a new Noir project with the following command:
noir new neg
Save the following code into src/main.noir:
fnmain(){let a:u32 = -1;}
Run nargo prove and observe the error.
Installation Method
Binary
Nargo Version
nargo 0.10.5 (git version hash: 9fe4cfd, is dirty: false)
Additional Context
No response
Would you like to submit a PR for this Issue?
No
Support Needs
No response
The text was updated successfully, but these errors were encountered:
The issue is not that -1 is forbidden, but rather the fact that -1-1 is allowed. This is because the check we perform is too simple.
We have a similar issue if you assign 300 to u8 vs 300+4 to u8.
Because we are moving toward preventing integer overflows, the solution is to error on overflows also in these cases
Aim
Noir throws an error saying that "u32 cannot be used in a unary operation" when directly assigning a negative integer literal to an unsigned integer type.
However, if you do some operations on the negative integer literal, the error is not thrown.
Expected Behavior
Noir should not throw an error when directly assigning a negative integer literal to an unsigned integer type.
Bug
Create a new Noir project with the following command:
Save the following code into
src/main.noir
:Run
nargo prove
and observe the following error:To see that the error is not thrown when doing some operations on the negative integer literal, save the following code into
src/main.noir
:Run
nargo prove
and observe that the error is not thrown.To Reproduce
Create a new Noir project with the following command:
Save the following code into
src/main.noir
:Run
nargo prove
and observe the error.Installation Method
Binary
Nargo Version
nargo 0.10.5 (git version hash: 9fe4cfd, is dirty: false)
Additional Context
No response
Would you like to submit a PR for this Issue?
No
Support Needs
No response
The text was updated successfully, but these errors were encountered: