Skip to content

Commit 8422e1f

Browse files
rchen152meta-codesync[bot]
authored andcommitted
Add Solver::solve_lower_bounds
Summary: Adds a (for now, unused) method to solver that solves a variable using its lower bounds. We first filter out `Any`, then union the bounds together. Needing to filter out `Any` is a little weird, but a bunch of tests break on the next diff with `Any` types popping up everywhere if I don't do it. For #105. Reviewed By: yangdanny97 Differential Revision: D96548933 fbshipit-source-id: 1be4ecf03996ee42c35886256480ecfe34fed1b2
1 parent b61d5ea commit 8422e1f

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

pyrefly/lib/solver/solver.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,16 @@ impl Solver {
943943
}
944944
}
945945

946+
#[expect(dead_code)]
947+
fn solve_lower_bounds(&self, mut lower_bounds: Vec<Type>) -> Type {
948+
// Keeping `Any` bounds causes `Any` to propagate to too many places,
949+
// so we filter them out unless `Any` is the only solution.
950+
if lower_bounds.iter().any(|t| !t.is_any()) {
951+
lower_bounds.retain(|t| !t.is_any());
952+
}
953+
unions(lower_bounds, &self.heap)
954+
}
955+
946956
/// Called after a quantified function has been called. Given `def f[T](x: int): list[T]`,
947957
/// after the generic has completed.
948958
/// If `infer_with_first_use` is true, the variable `T` will be have like an

0 commit comments

Comments
 (0)