Skip to content

fix: do not cast numeric to bool#14593

Merged
TomAFrench merged 5 commits intonextfrom
ab/do-not-cast-numeric-to-bool
May 29, 2025
Merged

fix: do not cast numeric to bool#14593
TomAFrench merged 5 commits intonextfrom
ab/do-not-cast-numeric-to-bool

Conversation

@asterite
Copy link
Contributor

@asterite asterite commented May 28, 2025

For noir-lang/noir#8703

In Noir, casting a number to bool is the same as casting that number to u1 first, then checking if that u1 is 0 or 1. That might be a bit unexpected, and actually in Rust you can't cast numbers to bool, so it's going to be disallowed soon.

This PR changes as bool to != 0 in most cases, though in some unpacking cases it seems the desired behavior was actually (value as u1) != 0, so there are a couple of those (without these a couple of tests fail).

@asterite asterite marked this pull request as draft May 28, 2025 20:22
@asterite asterite marked this pull request as ready for review May 28, 2025 21:16
@asterite asterite requested a review from nventuro May 28, 2025 21:22
Copy link
Contributor

@LeilaWang LeilaWang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this 🙌

@TomAFrench TomAFrench enabled auto-merge May 29, 2025 10:30
@TomAFrench TomAFrench added this pull request to the merge queue May 29, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks May 29, 2025
@TomAFrench TomAFrench added this pull request to the merge queue May 29, 2025
Merged via the queue into next with commit 8b957b9 May 29, 2025
4 checks passed
@TomAFrench TomAFrench deleted the ab/do-not-cast-numeric-to-bool branch May 29, 2025 12:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants