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 { match target {
Value::Dict(ref dict) => { Value::Dict(ref dict) => {
if matches!(dict.get(&field), Ok(Value::Func(_))) { if matches!(dict.get(&field), Ok(Value::Func(_))) {
error.hint( error.hint(eco_format!(
"to call the function stored in the dictionary, \ "to call the function stored in the dictionary, surround \
surround the field access with parentheses", the field access with parentheses, e.g. `(dict.{})(..)`",
); field.as_str(),
));
} else { } else {
field_hint(); field_hint();
} }

View File

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