From 4839dff6ab1ad6f5d195a3fbd37ec7900fc018cd Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sun, 26 Jul 2026 17:24:36 +0200 Subject: [PATCH] Chaining error: improve the error message --- parser/src/diagnostics.rs | 2 +- tests/by-util/test_awk.rs | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/parser/src/diagnostics.rs b/parser/src/diagnostics.rs index ca9b158..81d6fb9 100644 --- a/parser/src/diagnostics.rs +++ b/parser/src/diagnostics.rs @@ -170,7 +170,7 @@ impl ParsingError { "This is only valid in some contexts, like a right-hand assignment or a function argument.", ), Self::NonAssociativeOperator(_) => Some( - "Some operators can't be chained to avoid logical errors, such as comparison ones.\n\ + "Some operators cannot be chained because doing so could lead to logical errors. Comparison operators are one example.\n\ Example: write `a == b && b == c` instead of `a == b == c`.", ), Self::ExpectedIdentifier(_, _) => Some( diff --git a/tests/by-util/test_awk.rs b/tests/by-util/test_awk.rs index 74a993b..7fda4ae 100644 --- a/tests/by-util/test_awk.rs +++ b/tests/by-util/test_awk.rs @@ -249,6 +249,15 @@ fn write_to_dev_full_does_not_panic() { ); } +// Chaining non-associative operators must report the diagnostic's help text. +#[test] +fn chained_comparison_reports_help_text() { + ucmd() + .arg("BEGIN { p < q < r }") + .run() + .stderr_contains("Some operators cannot be chained"); +} + #[test] fn array_single_index_get_set() { ucmd()