mirror of
https://github.com/typst/typst
synced 2025-05-13 20:46:23 +08:00
hint for unknown variable containing dash (#924)
This commit is contained in:
parent
83c11f1ee4
commit
12129f0170
@ -42,7 +42,7 @@ impl<'a> Scopes<'a> {
|
||||
.chain(self.scopes.iter().rev())
|
||||
.chain(self.base.map(|base| base.global.scope()))
|
||||
.find_map(|scope| scope.get(var))
|
||||
.ok_or_else(|| eco_format!("unknown variable: {}", var))
|
||||
.ok_or_else(|| unknown_variable(var))
|
||||
}
|
||||
|
||||
/// Try to access a variable immutably in math.
|
||||
@ -62,12 +62,22 @@ impl<'a> Scopes<'a> {
|
||||
.ok_or_else(|| {
|
||||
match self.base.and_then(|base| base.global.scope().get(var)) {
|
||||
Some(_) => eco_format!("cannot mutate a constant: {}", var),
|
||||
_ => eco_format!("unknown variable: {}", var),
|
||||
_ => unknown_variable(var),
|
||||
}
|
||||
})?
|
||||
}
|
||||
}
|
||||
|
||||
/// The error message when a variable is not found.
|
||||
#[cold]
|
||||
fn unknown_variable(var: &str) -> EcoString {
|
||||
if var.contains('-') {
|
||||
eco_format!("unknown variable: {} – if you meant to use subtraction, try adding spaces around the minus sign.", var)
|
||||
} else {
|
||||
eco_format!("unknown variable: {}", var)
|
||||
}
|
||||
}
|
||||
|
||||
/// A map from binding names to values.
|
||||
#[derive(Default, Clone, Hash)]
|
||||
pub struct Scope(BTreeMap<EcoString, Slot>, bool);
|
||||
|
@ -3,4 +3,20 @@
|
||||
|
||||
---
|
||||
// Error: 1:17-1:19 expected length, found integer: a length needs a unit – did you mean 12pt?
|
||||
#set text(size: 12)
|
||||
#set text(size: 12)
|
||||
|
||||
---
|
||||
#{
|
||||
let a = 2
|
||||
a = 1-a
|
||||
a = a -1
|
||||
|
||||
// Error: 7-10 unknown variable: a-1 – if you meant to use subtraction, try adding spaces around the minus sign.
|
||||
a = a-1
|
||||
}
|
||||
|
||||
---
|
||||
#{
|
||||
// Error: 3-6 unknown variable: a-1 – if you meant to use subtraction, try adding spaces around the minus sign.
|
||||
a-1 = 2
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user