Skip to content

Commit

Permalink
Fix range used for flow merging in Expr::If
Browse files Browse the repository at this point in the history
Summary: We need to use a range that isn't used by anything else that calls merge_flow.

Reviewed By: migeed-z

Differential Revision: D68248102

fbshipit-source-id: ac498767c888ab563eb7bfc81b182069e6df79ab
  • Loading branch information
rchen152 authored and facebook-github-bot committed Jan 16, 2025
1 parent e45409a commit fdbaa64
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pyre2/pyre2/bin/binding/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ impl<'a> BindingsBuilder<'a> {
let narrow_ops = NarrowOps::from_expr(Some((*x.test).clone()));
self.bind_narrow_ops(&narrow_ops, x.body.range());
self.ensure_expr(&x.body);
self.negate_and_merge_flow(base, &narrow_ops, Some(&x.orelse), x.orelse.range());
self.negate_and_merge_flow(base, &narrow_ops, Some(&x.orelse), x.range());
return;
}
Expr::BoolOp(ExprBoolOp { range, op, values }) => {
Expand Down
9 changes: 9 additions & 0 deletions pyre2/pyre2/bin/test/flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -858,3 +858,12 @@ def f(x: None):
pass
"#,
);

// Regression test for a crash
testcase!(
test_ternary_and_or,
r#"
def f(x: bool, y: int):
return 0 if x else (y or 1)
"#,
);

0 comments on commit fdbaa64

Please sign in to comment.