From b4acd83c7827f8dd64fa1ded39530d3ed8e6d2ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nathalie=20Sch=C3=B6nwetter?= <1506194+Make-o-Rama@users.noreply.github.com> Date: Sun, 25 Oct 2026 01:48:21 +0000 Subject: [PATCH] A count from a length says how to get a count (#5901) (#6011) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A pattern count such as (L-2*Post)/210 is a length when the 210 is unit-less, and was refused with only "expected a unit-less number, got a length". The message now says to divide by a length, e.g. floor(L / (210 mm)). Co-authored-by: Nathalie Schönwetter Co-authored-by: Claude Sonnet 5.5 --- crates/doc/src/expr.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/crates/doc/src/expr.rs b/crates/doc/src/expr.rs index ffeda21a2..0af6e32a1 100644 --- a/crates/doc/src/expr.rs +++ b/crates/doc/src/expr.rs @@ -255,7 +255,12 @@ impl Value { Kind::Angle if self.unitless() => self.v * d.ang, Kind::Unitless if self.unitless() => self.v, _ => { - return Err(DocError::Expr(format!("expected {}, got {}", kind_word(k), self.describe()))); + let hint = if k == Kind::Unitless && self.len == 1 && self.ang == 0 { + " (a count needs a unit-less value: divide by a length, e.g. `floor(L / (210 mm))`)" + } else { + "" + }; + return Err(DocError::Expr(format!("expected {}, got {}{hint}", kind_word(k), self.describe()))); } }; if out.is_finite() { Ok(out) } else { Err(DocError::Expr("result is not a finite number".into())) } @@ -1141,6 +1146,16 @@ mod tests { assert_eq!(ev("width^2 / width", Kind::Length).unwrap(), 40.0); } + /// A count from a length (`(L - 20) / 210`, the 210 read as unit-less) names the fix (#5901). + #[test] + fn a_length_where_a_count_is_expected_says_to_divide_by_a_length() { + let e = ev("width / 2", Kind::Unitless).unwrap_err().to_string(); + assert!(e.contains("expected a unit-less number, got a length") && e.contains("divide by a length"), "{e}"); + assert_eq!(ev("floor(width / (6 mm))", Kind::Unitless).unwrap(), 6.0); + let e = ev("45 deg", Kind::Unitless).unwrap_err().to_string(); + assert!(!e.contains("divide"), "{e}"); + } + #[test] fn errors() { assert!(ev("width + ang", Kind::Length).is_err());