mirror of
https://github.com/typst/typst
synced 2025-05-14 04:56:26 +08:00
Add hint for missing method error for dictionary where a field with a function is present (#1922)
This commit is contained in:
parent
f6a4b8f97b
commit
046029b1e2
@ -173,7 +173,17 @@ pub fn call(
|
|||||||
"keys" => dict.keys().into_value(),
|
"keys" => dict.keys().into_value(),
|
||||||
"values" => dict.values().into_value(),
|
"values" => dict.values().into_value(),
|
||||||
"pairs" => dict.pairs().into_value(),
|
"pairs" => dict.pairs().into_value(),
|
||||||
_ => return missing(),
|
_ => {
|
||||||
|
return if matches!(dict.at(method, None), Ok(Value::Func(_))) {
|
||||||
|
Err(missing_method(name, method))
|
||||||
|
.hint(eco_format!(
|
||||||
|
"to call the function stored in the dictionary, surround the field access with parentheses"
|
||||||
|
))
|
||||||
|
.at(span)
|
||||||
|
} else {
|
||||||
|
missing()
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
Value::Func(func) => match method {
|
Value::Func(func) => match method {
|
||||||
|
@ -92,3 +92,23 @@
|
|||||||
---
|
---
|
||||||
// Error: 3-15 cannot mutate a temporary value
|
// Error: 3-15 cannot mutate a temporary value
|
||||||
#((key: "val").other = "some")
|
#((key: "val").other = "some")
|
||||||
|
|
||||||
|
---
|
||||||
|
#{
|
||||||
|
let dict = (
|
||||||
|
func: () => 1,
|
||||||
|
)
|
||||||
|
// Error: 3-14 type dictionary has no method `func`
|
||||||
|
// Hint: 3-14 to call the function stored in the dictionary, surround the field access with parentheses
|
||||||
|
dict.func()
|
||||||
|
}
|
||||||
|
|
||||||
|
---
|
||||||
|
#{
|
||||||
|
let dict = (
|
||||||
|
nonfunc: 1
|
||||||
|
)
|
||||||
|
|
||||||
|
// Error: 3-17 type dictionary has no method `nonfunc`
|
||||||
|
dict.nonfunc()
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user