Mercurial > vim
diff src/typval.c @ 22025:71f886a48ef5 v8.2.1562
patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Commit: https://github.com/vim/vim/commit/3767e3a3302d745349eff8cfe45411f03e13de43
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Sep 1 23:06:01 2020 +0200
patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Problem: Vim9: error when using "%" where a buffer is expected.
Solution: Add tv_get_buf_from_arg(). (closes https://github.com/vim/vim/issues/6814)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 01 Sep 2020 23:15:03 +0200 |
parents | 9fc27a955f00 |
children | 4bc644f4dd2d |
line wrap: on
line diff
--- a/src/typval.c +++ b/src/typval.c @@ -1562,4 +1562,23 @@ tv_get_buf(typval_T *tv, int curtab_only return buf; } +/* + * Like tv_get_buf() but give an error message is the type is wrong. + */ + buf_T * +tv_get_buf_from_arg(typval_T *tv) +{ + buf_T *buf; + + ++emsg_off; + buf = tv_get_buf(tv, FALSE); + --emsg_off; + if (buf == NULL + && tv->v_type != VAR_NUMBER + && tv->v_type != VAR_STRING) + // issue errmsg for type error + (void)tv_get_number(tv); + return buf; +} + #endif // FEAT_EVAL