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

"The bit count in a bit-shift operation must fit in a u8, try casting the right hand side into a u8 first" on a u8 value #5823

Closed
sirasistant opened this issue Aug 26, 2024 · 1 comment · Fixed by #5824
Labels
bug Something isn't working

Comments

@sirasistant
Copy link
Contributor

sirasistant commented Aug 26, 2024

Aim

Compile https://github.com/noir-lang/noir-bignum with latest noir

Expected Behavior

It should compile

Bug

error: The bit count in a bit-shift operation must fit in a u8, try casting the right hand side into a u8 first
    ┌─ src/utils/u60_representation.nr:198:46
    │
198 │         result.limbs.set(num_shifted_limbs, (value << limb_shift) & mask);
    │                                              -------------------
    │

error: The bit count in a bit-shift operation must fit in a u8, try casting the right hand side into a u8 first
    ┌─ src/utils/u60_representation.nr:204:29
    │
204 │             let upshift = ((value << limb_shift) + remainder) & mask;
    │                             -------------------
    │

But limb_shift is a u8 defined as let limb_shift = (shift % 60) as u8;

To Reproduce

Workaround

Yes

Workaround Description

Manually cast to u8 in the callsite

Additional Context

No response

Project Impact

None

Blocker Context

No response

Nargo Version

No response

NoirJS Version

No response

Proving Backend Tooling & Version

No response

Would you like to submit a PR for this Issue?

None

Support Needs

No response

@jfecher
Copy link
Contributor

jfecher commented Aug 26, 2024

This crate compiles and tests pass for me on

nargo version = 0.33.0
noirc version = 0.33.0+3e13b34a653ce5ce0894cf74b845399b4628bd05

Edit: I see you've updated the repo to workaround this. I'll undo it and try again.

github-merge-queue bot pushed a commit that referenced this issue Aug 26, 2024
# Description

## Problem\*

Resolves #5823

## Summary\*

We check `rhs` differently than `lhs` in left and right bit shifts in a
series of hacky checks.
In the case of type variables, `lhs` and `rhs` may be swapped causing
the unification to be placed on lhs instead of rhs. I've reordered the
cases to prevent this.

## Additional Context



## Documentation\*

Check one:
- [x] No documentation needed.
- [ ] Documentation included in this PR.
- [ ] **[For Experimental Features]** 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 Aug 26, 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

Successfully merging a pull request may close this issue.

2 participants