diff --git a/crates/nu-parser/src/parser.rs b/crates/nu-parser/src/parser.rs index f02cd0857a..b1ca82106e 100644 --- a/crates/nu-parser/src/parser.rs +++ b/crates/nu-parser/src/parser.rs @@ -3742,7 +3742,17 @@ pub fn parse_row_condition(working_set: &mut StateWorkingSet, spans: &[Span]) -> return expression; } _ => { - // We have an expression, so let's convert this into a block. + // We have an expression, check that it's compatible with bool + if !type_compatible(&Type::Bool, &expression.ty) { + working_set.error(ParseError::TypeMismatch( + Type::Bool, + expression.ty.clone(), + expression.span, + )); + return Expression::garbage(working_set, expression.span); + } + + // Convert this expression into a block. let mut block = Block::new(); let mut pipeline = Pipeline::new(); pipeline.elements.push(PipelineElement { diff --git a/tests/repl/test_parser.rs b/tests/repl/test_parser.rs index 45b890653c..0cc4bc4cfe 100644 --- a/tests/repl/test_parser.rs +++ b/tests/repl/test_parser.rs @@ -618,6 +618,11 @@ fn single_value_row_condition() -> TestResult { ) } +#[test] +fn row_condition_non_boolean() -> TestResult { + fail_test(r#"[1 2 3] | where 1"#, "expected bool") +} + #[test] fn performance_nested_lists() -> TestResult { // Parser used to be exponential on deeply nested lists