Mercurial > vim
diff src/userfunc.c @ 28008:cc7d54a134e4 v8.2.4529
patch 8.2.4529: Vim9: comparing partial with function fails
Commit: https://github.com/vim/vim/commit/ed0c62e7b16b62655824df28cdd6bd75aadbb8fc
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Mar 8 19:43:55 2022 +0000
patch 8.2.4529: Vim9: comparing partial with function fails
Problem: Vim9: comparing partial with function fails.
Solution: Support this comparison. Avoid a crash. (closes https://github.com/vim/vim/issues/9909)
Add more test cases.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 08 Mar 2022 20:45:03 +0100 |
parents | 02f787034998 |
children | b10fa9b17c85 |
line wrap: on
line diff
--- a/src/userfunc.c +++ b/src/userfunc.c @@ -5730,18 +5730,27 @@ func_has_abort( make_partial(dict_T *selfdict_in, typval_T *rettv) { char_u *fname; - ufunc_T *fp; + ufunc_T *fp = NULL; char_u fname_buf[FLEN_FIXED + 1]; int error; dict_T *selfdict = selfdict_in; - if (rettv->v_type == VAR_PARTIAL && rettv->vval.v_partial->pt_func != NULL) + if (rettv->v_type == VAR_PARTIAL && rettv->vval.v_partial != NULL + && rettv->vval.v_partial->pt_func != NULL) fp = rettv->vval.v_partial->pt_func; else { fname = rettv->v_type == VAR_FUNC ? rettv->vval.v_string + : rettv->vval.v_partial == NULL ? NULL : rettv->vval.v_partial->pt_name; - if (fname != NULL) + if (fname == NULL) + { + // There is no point binding a dict to a NULL function, just create + // a function reference. + rettv->v_type = VAR_FUNC; + rettv->vval.v_string = NULL; + } + else { char_u *tofree = NULL; @@ -5752,8 +5761,7 @@ make_partial(dict_T *selfdict_in, typval } } - if ((fp != NULL && (fp->uf_flags & FC_DICT)) - || (rettv->v_type == VAR_FUNC && rettv->vval.v_string == NULL)) + if (fp != NULL && (fp->uf_flags & FC_DICT)) { partial_T *pt = ALLOC_CLEAR_ONE(partial_T);