From fd2d6bd271e92c180089938456235692abcdaeb2 Mon Sep 17 00:00:00 2001 From: Bas Zalmstra Date: Wed, 1 Jan 2025 20:24:11 +0100 Subject: [PATCH] fix: issue where a union clause has no candidates --- src/solver/mod.rs | 12 ++++++++---- tests/solver.rs | 11 +++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/solver/mod.rs b/src/solver/mod.rs index c01997d..8b91ff4 100644 --- a/src/solver/mod.rs +++ b/src/solver/mod.rs @@ -1089,9 +1089,12 @@ impl Solver { // Find the first candidate that is not yet assigned a value or find the first // value that makes this clause true. - candidate = candidates - .iter() - .try_fold(None, |first_candidate, &candidate| { + candidate = candidates.iter().try_fold( + match candidate { + ControlFlow::Continue(x) => x, + _ => None, + }, + |first_candidate, &candidate| { let assigned_value = self.decision_tracker.assigned_value(candidate.into()); ControlFlow::Continue(match assigned_value { @@ -1137,7 +1140,8 @@ impl Solver { } }, }) - }); + }, + ); // Stop searching if we found a candidate that makes the clause true. if candidate.is_break() { diff --git a/tests/solver.rs b/tests/solver.rs index 389c1c9..de15d8a 100644 --- a/tests/solver.rs +++ b/tests/solver.rs @@ -1365,6 +1365,17 @@ fn test_snapshot_union_requirements() { )); } +#[test] +fn test_union_empty_requirements() { + let provider = BundleBoxProvider::from_packages(&[("a", 1, vec!["b 1 | c"]), ("b", 1, vec![])]); + + let result = solve_snapshot(provider, &["a"]); + assert_snapshot!(result, @r" + a=1 + b=1 + "); +} + #[test] fn test_root_constraints() { let provider =