Skip to content
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

fix: crash when a union requirement has no candidates #93

Merged
merged 1 commit into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/solver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1089,9 +1089,12 @@ impl<D: DependencyProvider, RT: AsyncRuntime> Solver<D, RT> {

// 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 {
Expand Down Expand Up @@ -1137,7 +1140,8 @@ impl<D: DependencyProvider, RT: AsyncRuntime> Solver<D, RT> {
}
},
})
});
},
);

// Stop searching if we found a candidate that makes the clause true.
if candidate.is_break() {
Expand Down
11 changes: 11 additions & 0 deletions tests/solver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
Loading