From 751ef6e8da6161a7235889f861506d210b722c90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrej=20Kol=C4=8Din?= Date: Mon, 11 Aug 2025 16:59:27 +0000 Subject: [PATCH] [parser] Improve type errors for boolean literals (#16408) Currently, strings `true` and `false` are intercepted early in parsing. Previously, if they didn't match the expected shape, the parse error said "expected non-boolean value". This PR changes the message to say "expected ". Because the parsing error requires a `&'static str` I had to add a `to_str(&self) -> &'static str` method on `SyntaxShape`. It's a bit crude for more complex shapes: it simply says `keyword`, `list`, `table`, and so on for them, without exposing the underlying structure. Fixes #16406 --- crates/nu-parser/src/parser.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/nu-parser/src/parser.rs b/crates/nu-parser/src/parser.rs index f7db2d5910..9c9522b474 100644 --- a/crates/nu-parser/src/parser.rs +++ b/crates/nu-parser/src/parser.rs @@ -5204,7 +5204,7 @@ pub fn parse_value( if matches!(shape, SyntaxShape::Boolean) || matches!(shape, SyntaxShape::Any) { return Expression::new(working_set, Expr::Bool(true), span, Type::Bool); } else { - working_set.error(ParseError::Expected("non-boolean value", span)); + working_set.error(ParseError::ExpectedWithStringMsg(shape.to_string(), span)); return Expression::garbage(working_set, span); } } @@ -5212,7 +5212,7 @@ pub fn parse_value( if matches!(shape, SyntaxShape::Boolean) || matches!(shape, SyntaxShape::Any) { return Expression::new(working_set, Expr::Bool(false), span, Type::Bool); } else { - working_set.error(ParseError::Expected("non-boolean value", span)); + working_set.error(ParseError::ExpectedWithStringMsg(shape.to_string(), span)); return Expression::garbage(working_set, span); } }