Fix if-branch pruning for Final bool constants#3571
Open
LeSingh1 wants to merge 5 commits into
Open
Conversation
When a name is annotated Final and assigned a bool literal, treat if/elif tests on that name like literal True/False so unreachable arms are pruned during binding. Fixes incorrect union types after if/else when the condition is always false or always true.
Contributor
|
The idea here makes sense, but the CI failures suggest this change may be leaking beyond Final-declared constants into general boolean control-flow inference. I’d double-check the branch pruning condition — it should ideally only trigger on Final-backed literals, not inferred constant truthiness. Might be worth adding a regression test for: non-Final bool literal assignment to ensure no accidental over-pruning. |
SysInfo derives Copy + Dupe (it's a thin Intern handle), so the clippy::trivially_copy_pass_by_ref lint flagged the &SysInfo parameter as needlessly indirect at deny-level. Switch the helper to take SysInfo by value and update the single call site. Fixes the deny-level clippy error blocking the pyrefly CI checks on this PR; no behavior change.
Commit e1416af ("Remove redundant pyrefly/rust-toolchain file") deleted pyrefly/rust-toolchain but left the pyrefly_wasm/rust-toolchain symlink which pointed at it. The dangling symlink fails 'stat' during Ubuntu CI setup with: Error: ENOENT: no such file or directory, stat '/home/runner/work/pyrefly/pyrefly/pyrefly_wasm/rust-toolchain' The root rust-toolchain.toml (channel = "stable") already takes precedence for the wasm build, per the rationale in e1416af, so the symlink served no purpose after that deletion. Remove it so this branch (and any other PR branched off current main) can finish CI setup.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #3537.
When a variable is declared
Finaland assigned a bool literal (FalseorTrue), control-flow tests likeif flag:now prune unreachable branches the same way as literalif False:/if True:.Before this change, both arms of an
if/elsecould contribute to merged types even when the condition was statically known to be always false viaFinal = False.Test plan
test_final_bool_unreachable_if_branch—Final = False→ else-only assignment typetest_final_bool_unreachable_else_branch—Final = True→ if-only assignment typecargo test test_final_bool_unreachable