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: Always ensure num_args is initialized #4027

Merged
merged 1 commit into from Aug 4, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/builder/arg.rs
Expand Up @@ -3984,6 +3984,14 @@ impl<'help> Arg<'help> {
if val_names_len > 1 {
self.settings.set(ArgSettings::MultipleValues);
self.num_vals.get_or_insert(val_names_len.into());
} else {
if self.is_multiple_values_set() {
self.num_vals.get_or_insert((1..).into());
} else if self.is_takes_value_set() {
self.num_vals.get_or_insert(1.into());
} else {
self.num_vals.get_or_insert(0.into());
}
}
}

Expand Down
15 changes: 9 additions & 6 deletions src/builder/debug_asserts.rs
Expand Up @@ -692,12 +692,15 @@ fn assert_arg(arg: &Arg) {

if let Some(num_vals) = arg.get_num_args() {
// This can be the cause of later asserts, so put this first
let num_val_names = arg.get_value_names().unwrap_or(&[]).len();
if num_vals.max_values() < num_val_names {
panic!(
"Argument {}: Too many value names ({}) compared to number_of_values ({})",
arg.name, num_val_names, num_vals
);
if num_vals != 0.into() {
// HACK: Don't check for flags to make the derive easier
let num_val_names = arg.get_value_names().unwrap_or(&[]).len();
if num_vals.max_values() < num_val_names {
panic!(
"Argument {}: Too many value names ({}) compared to number_of_values ({})",
arg.name, num_val_names, num_vals
);
}
}

assert_eq!(
Expand Down