-
Notifications
You must be signed in to change notification settings - Fork 123
binding: treat assert False
as terminating control flow
#603
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
Conversation
This change makes Pyrefly recognize `assert False` as a control flow terminator, similar to `raise`. It adds a call to `mark_flow_termination` when the assert condition is statically known to be `False`.
x = 10 | ||
assert False, "This assertion should cause control flow to terminate in this branch." | ||
# This line should be unreachable. | ||
raise Exception("Something unexpected happened here!") |
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.
I don't understand how this test demonstrates the difference the code change makes.
I would suggest marking the test function to return something like int
, and seeing if Pyrefly complains about implicit None return.
For example, here:
With your code change, the error in the second function will not be there.
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.
I've patched the test and added handling in another place that was missed
@yangdanny97 has imported this pull request. If you are a Meta employee, you can view this in D78165436. |
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.
Review automatically exported from Phabricator review in Meta.
@yangdanny97 merged this pull request in c83d376. |
This change makes Pyrefly recognize
assert False
as a control flow terminator, similar toraise
. It adds a call tomark_flow_termination
when the assert condition is statically known to beFalse
.closes #599