patch 8.1.1765: get(func, dict, def) does not work properly
Problem: get(func, dict, def) does not work properly.
Solution: Handle NULL dict better. (Takuya Fujiwara, closes #4734)
diff --git a/src/evalfunc.c b/src/evalfunc.c
index 804dbb4..449bc67 100644
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -4197,6 +4197,7 @@
dictitem_T *di;
dict_T *d;
typval_T *tv = NULL;
+ int what_is_dict = FALSE;
if (argvars[0].v_type == VAR_BLOB)
{
@@ -4270,7 +4271,11 @@
}
}
else if (STRCMP(what, "dict") == 0)
- rettv_dict_set(rettv, pt->pt_dict);
+ {
+ what_is_dict = TRUE;
+ if (pt->pt_dict != NULL)
+ rettv_dict_set(rettv, pt->pt_dict);
+ }
else if (STRCMP(what, "args") == 0)
{
rettv->v_type = VAR_LIST;
@@ -4284,7 +4289,11 @@
}
else
semsg(_(e_invarg2), what);
- return;
+
+ // When {what} == "dict" and pt->pt_dict == NULL, evaluate the
+ // third argument
+ if (!what_is_dict)
+ return;
}
}
else