Appends a hint if length is expected but hint provided. (#580)

This commit is contained in:
astrale-sharp 2023-04-05 16:47:12 +02:00 committed by GitHub
parent 222c590788
commit 085282c138
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 0 deletions

View File

@ -7,6 +7,8 @@ use ecow::EcoString;
use super::{Array, Str, Value};
use crate::diag::StrResult;
use crate::eval::Type;
use crate::geom::Length;
use crate::syntax::Spanned;
use crate::util::separated_list;
@ -291,6 +293,14 @@ impl CastInfo {
msg.push_str(", found ");
msg.push_str(found.type_name());
}
if_chain::if_chain! {
if let Value::Int(i) = found;
if parts.iter().any(|p| p == Length::TYPE_NAME);
if !matching_type;
then {
msg.push_str(&format!(": a length needs a unit did you mean {i}pt?"));
}
};
msg.into()
}

View File

@ -0,0 +1,6 @@
// Test diagnostics.
// Ref: false
---
// Error: 1:17-1:19 expected length, found integer: a length needs a unit did you mean 12pt?
#set text(size: 12)