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

Setting an unsigned type to negative values #3649

Closed
grasshopper47 opened this issue Nov 30, 2023 · 1 comment · Fixed by #3688
Closed

Setting an unsigned type to negative values #3649

grasshopper47 opened this issue Nov 30, 2023 · 1 comment · Fixed by #3688
Assignees
Labels
bug Something isn't working

Comments

@grasshopper47
Copy link
Contributor

grasshopper47 commented Nov 30, 2023

Aim

To be able to write:

let var : u8 = -1; // or global

Expected Behavior

That both examples compile and work in the exact same way.

Bug

Instead, a compilation error is thrown: error: u8 cannot be used in a unary operation

Yet doing:

let var = -1 as u8;

compiles and executes as expected with the previous code.

To Reproduce

See notes above

Installation Method

None

Nargo Version

nargo 0.19.4

Additional Context

No response

Would you like to submit a PR for this Issue?

No

Support Needs

No response

@grasshopper47 grasshopper47 added the bug Something isn't working label Nov 30, 2023
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir Nov 30, 2023
@guipublic
Copy link
Contributor

The first example works as expected because -1 is not a valid u8 number. Rust behaves similarly.

The second example does not work either because execution is failing. However it compiles fine as you indicate.
So the issue here is that the second example compiles.

github-merge-queue bot pushed a commit that referenced this issue Dec 6, 2023
# Description

## Problem\*

Resolves #3649 

## Summary\*

Forbid negation of unsigned integers

## Additional Context



## Documentation\*

Check one:
- [X] No documentation needed.
- [ ] Documentation included in this PR.
- [ ] **[Exceptional Case]** Documentation to be submitted in a separate
PR.

# PR Checklist\*

- [X] I have tested the changes locally.
- [X] I have formatted the changes with [Prettier](https://prettier.io/)
and/or `cargo fmt` on default settings.
@github-project-automation github-project-automation bot moved this from 📋 Backlog to ✅ Done in Noir Dec 6, 2023
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.

2 participants