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 <nathalie@cfw-ag.ch> Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 file changed
+16
-1
+16
-1
@@ -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());
|
||||
|
||||
Reference in new issue
Block a user