Patch 8.2.3299
Problem: Vim9: exists() does not handle much at compile time.
Solution: Handle variable names. (closes #8688)
Files: src/vim9compile.c, src/evalfunc.c,
src/testdir/test_vim9_builtin.vim
*** ../vim-8.2.3298/src/vim9compile.c 2021-08-05 20:39:59.354053658 +0200
--- src/vim9compile.c 2021-08-05 22:42:18.820972933 +0200
***************
*** 3417,3424 ****
s = skipwhite(s);
if (*s == ')' && argvars[0].v_type == VAR_STRING
&& ((is_has && !dynamic_feature(argvars[0].vval.v_string))
! || (!is_has && (*argvars[0].vval.v_string == '+'
! || *argvars[0].vval.v_string == '&'))))
{
typval_T *tv = &ppconst->pp_tv[ppconst->pp_used];
--- 3417,3424 ----
s = skipwhite(s);
if (*s == ')' && argvars[0].v_type == VAR_STRING
&& ((is_has && !dynamic_feature(argvars[0].vval.v_string))
! || (!is_has && vim_strchr((char_u *)"+&:*",
! *argvars[0].vval.v_string))))
{
typval_T *tv = &ppconst->pp_tv[ppconst->pp_used];
*** ../vim-8.2.3298/src/evalfunc.c 2021-08-02 20:06:44.351011164 +0200
--- src/evalfunc.c 2021-08-05 22:31:21.813503845 +0200
***************
*** 3552,3558 ****
--- 3552,3565 ----
}
else if (*p == '*') // internal or user defined
function
{
+ int save_version = current_sctx.sc_version;
+
+ // Vim9 script assumes a function is script-local, but here we want to
+ // find any matching function.
+ if (current_sctx.sc_version == SCRIPT_VERSION_VIM9)
+ current_sctx.sc_version = SCRIPT_VERSION_MAX;
n = function_exists(p + 1, FALSE);
+ current_sctx.sc_version = save_version;
}
else if (*p == '?') // internal function only
{
*** ../vim-8.2.3298/src/testdir/test_vim9_builtin.vim 2021-08-02
20:06:44.355011158 +0200
--- src/testdir/test_vim9_builtin.vim 2021-08-05 22:43:12.928896468 +0200
***************
*** 787,792 ****
--- 787,794 ----
CheckDefExecFailure(['echo exepath("")'], 'E1175:')
enddef
+ command DoSomeCommand let g:didSomeCommand = 4
+
def Test_exists()
CheckDefAndScriptFailure2(['exists(10)'], 'E1013: Argument 1: type
mismatch, expected string but got number', 'E1174: String required for argument
1')
call assert_equal(1, exists('&tabstop'))
***************
*** 809,814 ****
--- 811,836 ----
else
assert_report('tabstop option not existing?')
endif
+
+ if exists(':DoSomeCommand') >= 2
+ DoSomeCommand
+ endif
+ assert_equal(4, g:didSomeCommand)
+ if exists(':NoSuchCommand') >= 2
+ NoSuchCommand
+ endif
+
+ var found = false
+ if exists('*CheckScriptSuccess')
+ found = true
+ endif
+ assert_true(found)
+ if exists('*NoSuchFunction')
+ NoSuchFunction()
+ endif
+ if exists('*no_such_function')
+ no_such_function()
+ endif
enddef
def Test_expand()
***************
*** 2948,2954 ****
assert_fails('setreg("ab", 0)', 'E1162:')
CheckDefAndScriptFailure2(['setreg(1, "b")'], 'E1013: Argument 1: type
mismatch, expected string but got number', 'E1174: String required for argument
1')
CheckDefAndScriptFailure2(['setreg("a", "b", 3)'], 'E1013: Argument 3: type
mismatch, expected string but got number', 'E1174: String required for argument
3')
! enddef
def Test_settabvar()
CheckDefAndScriptFailure2(['settabvar("a", "b", 1)'], 'E1013: Argument 1:
type mismatch, expected number but got string', 'E1210: Number required for
argument 1')
--- 2970,2976 ----
assert_fails('setreg("ab", 0)', 'E1162:')
CheckDefAndScriptFailure2(['setreg(1, "b")'], 'E1013: Argument 1: type
mismatch, expected string but got number', 'E1174: String required for argument
1')
CheckDefAndScriptFailure2(['setreg("a", "b", 3)'], 'E1013: Argument 3: type
mismatch, expected string but got number', 'E1174: String required for argument
3')
! enddef
def Test_settabvar()
CheckDefAndScriptFailure2(['settabvar("a", "b", 1)'], 'E1013: Argument 1:
type mismatch, expected number but got string', 'E1210: Number required for
argument 1')
*** ../vim-8.2.3298/src/version.c 2021-08-05 21:17:28.759789450 +0200
--- src/version.c 2021-08-05 21:58:12.344768954 +0200
***************
*** 757,758 ****
--- 757,760 ----
{ /* Add new patch number below this line */
+ /**/
+ 3299,
/**/
--
CUSTOMER: You're not fooling anyone y'know. Look, isn't there something
you can do?
DEAD PERSON: I feel happy... I feel happy.
[whop]
CUSTOMER: Ah, thanks very much.
MORTICIAN: Not at all. See you on Thursday.
CUSTOMER: Right.
The Quest for the Holy Grail (Monty Python)
/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_dev/202108052049.175KnDJU1405773%40masaka.moolenaar.net.