Clarify the way to access functions from dictionaries (#3064)

Co-authored-by: Laurenz <laurmaedje@gmail.com>
This commit is contained in:
Leedehai 2024-01-02 04:13:45 -05:00 committed by GitHub
parent 527d63ed25
commit 39e53fcdc9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 8 deletions

View File

@ -110,10 +110,11 @@ impl Eval for ast::FuncCall<'_> {
match target {
Value::Dict(ref dict) => {
if matches!(dict.get(&field), Ok(Value::Func(_))) {
error.hint(
"to call the function stored in the dictionary, \
surround the field access with parentheses",
);
error.hint(eco_format!(
"to call the function stored in the dictionary, surround \
the field access with parentheses, e.g. `(dict.{})(..)`",
field.as_str(),
));
} else {
field_hint();
}

View File

@ -105,11 +105,11 @@
---
#{
let dict = (
func: () => 1,
call-me: () => 1,
)
// Error: 8-12 type dictionary has no method `func`
// Hint: 8-12 to call the function stored in the dictionary, surround the field access with parentheses
dict.func()
// Error: 8-15 type dictionary has no method `call-me`
// Hint: 8-15 to call the function stored in the dictionary, surround the field access with parentheses, e.g. `(dict.call-me)(..)`
dict.call-me()
}
---