diff --git a/crates/nu-command/tests/commands/def.rs b/crates/nu-command/tests/commands/def.rs index c39e89ada2..0ec13c0511 100644 --- a/crates/nu-command/tests/commands/def.rs +++ b/crates/nu-command/tests/commands/def.rs @@ -172,19 +172,6 @@ fn def_default_value_should_restrict_implicit_type() { assert!(actual2.err.contains("expected int")); } -#[test] -fn def_boolean_flags() { - let actual = nu!("def foo [--x: bool] { $x }; foo --x"); - assert!(actual.err.contains("flag missing bool argument")); - let actual = nu!("def foo [--x: bool = false] { $x }; foo"); - assert_eq!(actual.out, "false"); - let actual = nu!("def foo [--x: bool = false] { $x }; foo --x"); - assert!(actual.err.contains("flag missing bool argument")); - // boolean flags' default value should be null - let actual = nu!("def foo [--x: bool] { $x == null }; foo"); - assert_eq!(actual.out, "true"); -} - #[test] fn def_wrapped_with_block() { let actual = nu!( diff --git a/crates/nu-parser/src/parser.rs b/crates/nu-parser/src/parser.rs index 6e1ab7fc6f..a89b0dfdaa 100644 --- a/crates/nu-parser/src/parser.rs +++ b/crates/nu-parser/src/parser.rs @@ -18,8 +18,8 @@ use nu_protocol::{ }, engine::StateWorkingSet, eval_const::eval_constant, - span, BlockId, DidYouMean, Flag, ParseError, ParseWarning, PositionalArg, Signature, Span, - Spanned, SyntaxShape, Type, Unit, VarId, ENV_VARIABLE_ID, IN_VARIABLE_ID, + span, BlockId, DidYouMean, Flag, ParseError, PositionalArg, Signature, Span, Spanned, + SyntaxShape, Type, Unit, VarId, ENV_VARIABLE_ID, IN_VARIABLE_ID, }; use crate::parse_keywords::{ @@ -3603,9 +3603,9 @@ pub fn parse_signature_helper(working_set: &mut StateWorkingSet, span: Span) -> } => { working_set.set_variable_type(var_id.expect("internal error: all custom parameters must have var_ids"), syntax_shape.to_type()); if syntax_shape == SyntaxShape::Boolean { - working_set.warning(ParseWarning::DeprecatedWarning( - "--flag: bool".to_string(), - "--flag".to_string(), + working_set.error(ParseError::LabeledError( + "Type annotations are not allowed for boolean switches.".to_string(), + "Remove the `: bool` type annotation.".to_string(), span, )); } diff --git a/src/tests/test_custom_commands.rs b/src/tests/test_custom_commands.rs index 48e575a14b..fe6f8dfa76 100644 --- a/src/tests/test_custom_commands.rs +++ b/src/tests/test_custom_commands.rs @@ -149,8 +149,7 @@ fn custom_flag2() -> TestResult { #[test] fn deprecated_boolean_flag() { let actual = nu!(r#"def florb [--dry-run: bool, --another-flag] { "aaa" }; florb"#); - assert!(actual.err.contains("Deprecated")); - assert_eq!(actual.out, "aaa"); + assert!(actual.err.contains("not allowed")); } #[test]