-
Notifications
You must be signed in to change notification settings - Fork 3
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
Add rule for rand(Bool)
instead of rand() < 0.5
#14
base: main
Are you sure you want to change the base?
Conversation
43137c8
to
b692572
Compare
The fix does not remove the assignment in cases like: x = rand()
if x < 0.5
...
end This fixes to: x = rand()
if rand(Bool)
...
end |
This is different code semantically. If Take this section of code for instance: x = rand()
if x < 0.5
y = sqrt(0.5 - x)
end Under this transformation, it is now possible to end up with a domain error in the square root when it wasn't before - because if this is transformed to x = rand()
if rand(Bool)
y = sqrt(0.5 - x)
end then there is no longer a guarantee that |
I hadn't thought of that! I would say then either just remove the autofix, or remove altogether the pattern that checks for assigning |
Other ideas:
|
maybe this is the best way forward? |
I split it in two rules. The test files are the same, only the rule names differ (and the tests they pass/fail for of course). The name for the second rule is not very inspired... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Can we add a description of some sort in the rule definition files so that I'm not confused when I see this in a few months?
After this Slack thread.