mirror of
https://github.com/typst/typst
synced 2025-05-14 04:56:26 +08:00
Appends a hint if length is expected but hint provided. (#580)
This commit is contained in:
parent
222c590788
commit
085282c138
@ -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()
|
||||
}
|
||||
|
6
tests/typ/compiler/hint.typ
Normal file
6
tests/typ/compiler/hint.typ
Normal 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)
|
Loading…
x
Reference in New Issue
Block a user