diff --git a/crates/nu-cmd-lang/src/core_commands/do_.rs b/crates/nu-cmd-lang/src/core_commands/do_.rs index 6c94f9eaa1..0360bb35b9 100644 --- a/crates/nu-cmd-lang/src/core_commands/do_.rs +++ b/crates/nu-cmd-lang/src/core_commands/do_.rs @@ -264,7 +264,7 @@ fn bind_args_to( .expect("internal error: all custom parameters must have var_ids"); if let Some(result) = val_iter.next() { let param_type = param.shape.to_type(); - if required && !result.is_subtype_of(¶m_type) { + if !result.is_subtype_of(¶m_type) { return Err(ShellError::CantConvert { to_type: param.shape.to_type().to_string(), from_type: result.get_type().to_string(), diff --git a/crates/nu-command/tests/commands/do_.rs b/crates/nu-command/tests/commands/do_.rs index 606c534073..5cf2279e7b 100644 --- a/crates/nu-command/tests/commands/do_.rs +++ b/crates/nu-command/tests/commands/do_.rs @@ -60,3 +60,17 @@ fn run_closure_with_it_using() { assert!(actual.err.is_empty()); assert_eq!(actual.out, "3"); } + +#[test] +fn required_argument_type_checked() { + let actual = nu!(r#"do {|x: string| $x} 4"#); + assert!(actual.out.is_empty()); + assert!(actual.err.contains("nu::shell::cant_convert")); +} + +#[test] +fn optional_argument_type_checked() { + let actual = nu!(r#"do {|x?: string| $x} 4"#); + assert_eq!(actual.out, ""); + assert!(actual.err.contains("nu::shell::cant_convert")); +}